-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWaifuRepo.js
38 lines (33 loc) · 1.01 KB
/
WaifuRepo.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
const WaifuBridge = require('./WaifuBridge')
const WaifuModel = require('./WaifuModel')
const { buildWaifu } = require('./helper')
const { addWaifusPopCount } = require('./waifuRepoMethod/addWaifusPopCount')
/**
* @typedef {import('./Waifu').ModeConfig} ModeConfig
*/
exports.addWaifusPopCount = addWaifusPopCount
exports.getList = async function () {
/**
* @type {Array}
*/
const objList = await WaifuBridge.getList()
return objList.map(buildWaifu)
}
exports.getByUrlId = async function (urlId) {
const obj = await WaifuBridge.getByUrlId(urlId)
return obj ? buildWaifu(obj) : undefined
}
/**
* @param {Object} waifuData
* @param {String} waifuData.urlId
* @param {String} waifuData.name
* @param {Array<ModeConfig>} waifuData.modeConfigList
*/
exports.upsertWaifu = async function ({ urlId, name, modeConfigList }) {
const obj = await WaifuModel.findOneAndUpdate(
{ urlId },
{ name, modeConfigList },
{ new: true, upsert: true, setDefaultsOnInsert: true }
).lean()
return buildWaifu(obj)
}