-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5996239
commit 43b7da6
Showing
7 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {firebaseConfig} from "./src/environments/firebase.config"; | ||
import {initializeApp, auth,database} from 'firebase'; | ||
const Queue = require('firebase-queue'); | ||
import Promise from "ts-promise"; | ||
|
||
|
||
console.log('Running batch server ...'); | ||
|
||
initializeApp(firebaseConfig); | ||
|
||
auth() | ||
.signInWithEmailAndPassword('two@admin.com', 'admin123') | ||
.then(runConsumer) | ||
.catch(onError); | ||
|
||
function onError(err) { | ||
console.error("Could not login", err); | ||
process.exit(); | ||
} | ||
|
||
|
||
function runConsumer() { | ||
|
||
console.log("Running consumer ..."); | ||
|
||
const lessonsRef = database().ref("lessons"); | ||
const lessonsPerCourseRef = database().ref("lessonsPerCourse"); | ||
|
||
const queueRef = database().ref('queue'); | ||
|
||
|
||
const queue = new Queue(queueRef, function(data, progress, resolve, reject) { | ||
|
||
console.log('received delete request ...',data); | ||
|
||
const deleteLessonPromise = lessonsRef.child(data.lessonId).remove(); | ||
|
||
const deleteLessonPerCoursePromise = | ||
lessonsPerCourseRef.child(`${data.courseId}/${data.lessonId}`).remove(); | ||
|
||
Promise.all([deleteLessonPromise, deleteLessonPerCoursePromise]) | ||
.then( | ||
() => { | ||
console.log("lesson deleted"); | ||
resolve(); | ||
} | ||
) | ||
.catch(() => { | ||
console.log("lesson deletion in error"); | ||
reject(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ | |
"target": "es5", | ||
"typeRoots": [ | ||
"../node_modules/@types" | ||
], | ||
"types": [ | ||
"node", | ||
"firebase" | ||
] | ||
} | ||
} |