Skip to content
This repository was archived by the owner on May 13, 2021. It is now read-only.

Commit b688528

Browse files
committed
adds not found check!
1 parent cf29d2c commit b688528

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/getProgram.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const firestore = require("../firebase");
22
const winston = require("winston");
3+
const helpers = require("./helpers");
34

45
/**---------getProgram--------------
56
* retrieves a program document
@@ -27,7 +28,16 @@ const getProgram = async function(docID) {
2728
.collection("/programs")
2829
.doc(docID)
2930
.get();
30-
winston.info(`Got doc. Returning...`);
31+
winston.info(`Got doc. Checking if empty...`);
32+
if (helpers.isObjectEmpty(doc.data())) {
33+
winston.info(`Empty => doc does not exist. Returning...`);
34+
winston.error(`Sketch with key ${docID} not found`);
35+
return {
36+
ok: false,
37+
error: `Sketch with key ${docID} not found`,
38+
};
39+
}
40+
winston.info(`Doc exists, returning...`);
3141
return {
3242
ok: true,
3343
sketch: doc.data(),

lib/helpers.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const isObjectEmpty = function(obj) {
2+
for (var key in obj) {
3+
if (obj.hasOwnProperty(key)) return false;
4+
}
5+
return true;
6+
};
7+
8+
module.exports = {
9+
isObjectEmpty,
10+
};

0 commit comments

Comments
 (0)