Repository navigation
Expand file tree
/
Copy pathfacade.ts
More file actions
61 lines (51 loc) · 1.86 KB
/
Copy pathfacade.ts
File metadata and controls
61 lines (51 loc) · 1.86 KB
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
class Facade {
Schema: any;
constructor(Schema: any) {
this.Schema = Schema;
}
create(input: any): any {
return this.Schema.create(input);
}
async find(query: any): Promise<any> {
let result;
try { result = await this.Schema.find(query).lean().exec(); } catch (e) { return Promise.reject(e); }
return Promise.resolve(result);
}
async findSort(query: any, sort: any): Promise<any> {
let result;
try { result = await this.Schema.find(query).sort(sort).lean().exec(); } catch (e) { return Promise.reject(e); }
return Promise.resolve(result);
}
deleteMany(query: any): any {
return this.Schema.deleteMany(query);
}
// async findOne(query) {
// let result;
// try { result = await this.Schema.findOne(query).lean().exec(); } catch (e) { return Promise.reject(e); }
// return Promise.resolve(result);
// }
// async findOneAndUpdate(conditions, update) {
// let result;
// try {
// result = await this.Schema.findOneAndUpdate(conditions, update, { new: true }).lean().exec();
// } catch (e) { return Promise.reject(e); }
// return Promise.resolve(result);
// }
findByIdAndUpdate(id: any, update: any): any {
return this.Schema.findByIdAndUpdate(id, update, { new: true }).lean().exec();
}
//
// findById(id) {
// return this.Schema.findById(id).lean().exec();
// }
//
// Mongoose 9.x removed `findByIdAndRemove` entirely (both on Model and
// Query) in favor of `findByIdAndDelete` (JaMmusic#1199) — calling the old
// name here threw synchronously, which the caller silently swallowed, so
// deletes never took effect. Keep this method's own name (`findByIdAndRemove`)
// unchanged since Controller/GigController/JamPicsController call it.
findByIdAndRemove(id: any): any {
return this.Schema.findByIdAndDelete(id).lean().exec();
}
}
export default Facade;