-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfirmware_check.js
44 lines (41 loc) · 1005 Bytes
/
firmware_check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const mongojs = require("mongojs");
const db = mongojs();
const col = db.collection("motofirmwares");
module.exports = function (type, sku, carrier, next) {
switch (type) {
case "pn":
col.find({ sn: sku }, (err, docs) => {
if (docs && docs.length > 0) {
return next(docs);
}
return next();
});
break;
case "devicename":
case "version":
case "key":
col.find({ name: { $regex: sku, $options: "i" } }, (err, docs) => {
if (docs && docs.length > 0) {
return next(docs);
}
return next();
});
break;
case "sku":
col.find(
{
$and: [
{ phones: { $regex: sku, $options: "i" } },
{ carrier: { $regex: carrier, $options: "i" } },
],
},
(err, docs) => {
if (err) console.log(err);
if (docs && docs.length > 0) {
return next(docs);
}
}
);
break;
}
};