-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.js
64 lines (59 loc) · 1.94 KB
/
admin.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
/*!
* Module dependencies.
*/
const Debug = require('debug'); // https://github.com/visionmedia/debug
const utilities = require('./utilities.js');
/**
* Class for admin stuff, e.g list all shops where the app is installed,
* so this should not be accessable by single app users, just for admins
* @alias shopify-server/Admin
*/
class Admin {
/**
* Create an admin object
*/
constructor() {
this.debug = new Debug('shopify-server:admin');
};
/**
* Get all shops where the app is installed
* @param {Object} firebaseApp
* @return {Promise<Array>} - A promise to an array of shop datas object
*/
shopsList(firebaseApp) {
return new Promise((fulfill, reject) => {
let db = firebaseApp.database();
let ref = db.ref('/shopifyAccessToken');
ref.once('value', (snapshot) => {
let values = snapshot.val(); // null if empty
this.debug('admin.shop.list: ', values);
let splits = [];
if (values !== null) {
Object.keys(values).map((key, index) => {
let shopData = utilities.getShopByFirebaseUID(key);
let split = {
uid: key,
shop: shopData.shop,
shopName: shopData.shopName,
accessToken: values[key],
};
splits.push(split);
this.debug(split);
});
}
fulfill(splits);
}, (errorObject) => {
this.debug(errorObject);
reject(errorObject);
});
});
};
}
/**
* Admin stuff, e.g list all shops where the app is installed,
* so this should not be accessable by single app users, just for admins
* @module shopify-server/admin
* @see {@link Admin}
*/
module.exports = Admin;