|
@@ -39,7 +39,7 @@ class CrudService extends NafService {
|
|
|
* @param {Object} update 数据
|
|
|
* @return {Object} 返回查询条件和数据
|
|
|
*/
|
|
|
- async berforeUpdate(filter, update) {
|
|
|
+ async beforeUpdate(filter, update) {
|
|
|
return { filter, update };
|
|
|
}
|
|
|
|
|
@@ -58,9 +58,9 @@ class CrudService extends NafService {
|
|
|
async update(filter, update, { projection } = {}) {
|
|
|
assert(filter);
|
|
|
assert(update);
|
|
|
- const berforeUpdateResult = await this.berforeUpdate(filter, update);
|
|
|
- filter = berforeUpdateResult.filter;
|
|
|
- update = berforeUpdateResult.update;
|
|
|
+ const beforeUpdateResult = await this.beforeUpdate(filter, update);
|
|
|
+ filter = beforeUpdateResult.filter;
|
|
|
+ update = beforeUpdateResult.update;
|
|
|
const { _id, id } = filter;
|
|
|
if (_id || id) filter = { _id: ObjectId(_id || id) };
|
|
|
// TODO:检查数据是否存在
|
|
@@ -128,7 +128,7 @@ class CrudService extends NafService {
|
|
|
if (sort && isString(sort)) {
|
|
|
sort = { [sort]: desc ? -1 : 1 };
|
|
|
} else if (sort && isArray(sort)) {
|
|
|
- sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
|
|
|
+ sort = sort.map((f) => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
|
|
|
}
|
|
|
let res = await this.model.findOne(filter, projection).exec();
|
|
|
res = await this.afterFetch(filter, res);
|
|
@@ -147,7 +147,7 @@ class CrudService extends NafService {
|
|
|
if (sort && isString(sort)) {
|
|
|
sort = { [sort]: desc ? -1 : 1 };
|
|
|
} else if (sort && isArray(sort)) {
|
|
|
- sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
|
|
|
+ sort = sort.map((f) => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
|
|
|
}
|
|
|
let condition = cloneDeep(filter);
|
|
|
condition = await this.beforeQuery(condition);
|
|
@@ -170,12 +170,12 @@ class CrudService extends NafService {
|
|
|
|
|
|
// 过滤出ref字段
|
|
|
const refMods = await this.getRefMods();
|
|
|
- const populate = refMods.map(i => i.col);
|
|
|
+ const populate = refMods.map((i) => i.col);
|
|
|
// 带ref查询
|
|
|
let rs = await this.model.find(trimData(condition), projection, { skip, limit, sort }).populate(populate).exec();
|
|
|
rs = JSON.parse(JSON.stringify(rs));
|
|
|
// 整理ref数据
|
|
|
- rs = rs.map(i => {
|
|
|
+ rs = rs.map((i) => {
|
|
|
for (const obj of refMods) {
|
|
|
const { col, prop, type } = obj;
|
|
|
if (!prop) continue;
|