itlab-internal-services 2.16.1 → 2.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/document/commentable-document.class.d.ts +200 -0
- package/dist/classes/document/commentable-document.class.js +24 -0
- package/dist/classes/document/content-document.class.d.ts +200 -0
- package/dist/classes/document/content-document.class.js +24 -0
- package/dist/classes/document/index.d.ts +4 -0
- package/dist/classes/document/index.js +11 -0
- package/dist/classes/document/likeable-document.class.d.ts +205 -0
- package/dist/classes/document/likeable-document.class.js +70 -0
- package/dist/classes/document/viewable-document.class.d.ts +205 -0
- package/dist/classes/document/viewable-document.class.js +67 -0
- package/dist/classes/document-updater.class.d.ts +40 -0
- package/dist/classes/document-updater.class.js +58 -0
- package/dist/classes/fetch-options/base-options.class.d.ts +18 -0
- package/dist/classes/fetch-options/base-options.class.js +81 -0
- package/dist/classes/fetch-options/comments-options.class.d.ts +6 -0
- package/dist/classes/fetch-options/comments-options.class.js +26 -0
- package/dist/classes/fetch-options/content-options.class.d.ts +7 -0
- package/dist/classes/fetch-options/content-options.class.js +32 -0
- package/dist/classes/fetch-options/drafted-options.class.d.ts +9 -0
- package/dist/classes/fetch-options/drafted-options.class.js +34 -0
- package/dist/classes/fetch-options/index.d.ts +6 -0
- package/dist/classes/fetch-options/index.js +15 -0
- package/dist/classes/fetch-options/liked-by-options.class.d.ts +8 -0
- package/dist/classes/fetch-options/liked-by-options.class.js +28 -0
- package/dist/classes/fetch-options/viewed-by-options.class.d.ts +9 -0
- package/dist/classes/fetch-options/viewed-by-options.class.js +28 -0
- package/dist/classes/index.d.ts +2 -2
- package/dist/classes/index.js +17 -3
- package/dist/classes/task-manager.class.d.ts +2 -2
- package/dist/classes/task-manager.class.js +4 -0
- package/dist/decorators/has-permission.decorator.d.ts +3 -0
- package/dist/decorators/has-permission.decorator.js +26 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/jwt.decorator.d.ts +1 -1
- package/dist/decorators/jwt.decorator.js +13 -11
- package/dist/decorators/schema-with-critical-keys.decorator.d.ts +12 -0
- package/dist/decorators/schema-with-critical-keys.decorator.js +16 -0
- package/dist/factories/index.d.ts +1 -0
- package/dist/factories/index.js +5 -0
- package/dist/factories/virtuals.factory.d.ts +80 -0
- package/dist/factories/virtuals.factory.js +172 -0
- package/dist/functions/create-schema.function.d.ts +3 -0
- package/dist/functions/create-schema.function.js +33 -0
- package/dist/functions/index.d.ts +1 -1
- package/dist/functions/index.js +3 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/likeable.interface.d.ts +42 -0
- package/dist/likeable.interface.js +48 -0
- package/dist/modules/_old/comment/comment.controller.d.ts +35 -0
- package/dist/modules/_old/comment/comment.controller.js +86 -0
- package/dist/modules/_old/comment/comment.model.d.ts +29 -0
- package/dist/modules/_old/comment/comment.model.js +43 -0
- package/dist/modules/_old/comment/comment.module-definition.d.ts +45 -0
- package/dist/modules/{comment → _old/comment}/comment.module-definition.js +2 -1
- package/dist/modules/_old/comment/comment.module.d.ts +22 -0
- package/dist/modules/_old/comment/comment.module.js +71 -0
- package/dist/modules/_old/comment/comment.service.d.ts +54 -0
- package/dist/modules/_old/comment/comment.service.js +133 -0
- package/dist/modules/_old/comment/index.d.ts +3 -0
- package/dist/modules/_old/comment/index.js +9 -0
- package/dist/modules/_old/content/content.module-definition.d.ts +5 -0
- package/dist/modules/_old/content/content.module-definition.js +8 -0
- package/dist/modules/_old/content/content.module.d.ts +31 -0
- package/dist/modules/_old/content/content.module.js +60 -0
- package/dist/modules/_old/content/content.service.d.ts +50 -0
- package/dist/modules/_old/content/content.service.js +145 -0
- package/dist/modules/_old/content/index.d.ts +2 -0
- package/dist/modules/_old/content/index.js +7 -0
- package/dist/modules/_old/database/database-module-options.interface.d.ts +41 -0
- package/dist/modules/_old/database/database.liveness-controller.d.ts +27 -0
- package/dist/modules/_old/database/database.liveness-controller.js +80 -0
- package/dist/modules/_old/database/database.module.d.ts +41 -0
- package/dist/modules/_old/database/database.module.js +97 -0
- package/dist/modules/_old/database/index.d.ts +6 -0
- package/dist/modules/_old/database/index.js +13 -0
- package/dist/modules/_old/database/lock-service/lock.schema.d.ts +38 -0
- package/dist/modules/_old/database/lock-service/lock.schema.js +51 -0
- package/dist/modules/_old/database/lock-service/lock.service.d.ts +53 -0
- package/dist/modules/_old/database/lock-service/lock.service.js +103 -0
- package/dist/modules/_old/database/model-service/dbs/hub-account.db.d.ts +28 -0
- package/dist/modules/_old/database/model-service/dbs/hub-account.db.js +44 -0
- package/dist/modules/_old/database/model-service/dbs/hub-books.db.d.ts +23 -0
- package/dist/modules/_old/database/model-service/dbs/hub-books.db.js +45 -0
- package/dist/modules/_old/database/model-service/dbs/hub-comments.db.d.ts +29 -0
- package/dist/modules/_old/database/model-service/dbs/hub-comments.db.js +68 -0
- package/dist/modules/_old/database/model-service/dbs/hub-content.db.d.ts +24 -0
- package/dist/modules/_old/database/model-service/dbs/hub-content.db.js +49 -0
- package/dist/modules/_old/database/model-service/dbs/hub-demo-hive.db.d.ts +23 -0
- package/dist/modules/_old/database/model-service/dbs/hub-demo-hive.db.js +45 -0
- package/dist/modules/_old/database/model-service/dbs/hub-events.db.d.ts +24 -0
- package/dist/modules/_old/database/model-service/dbs/hub-events.db.js +49 -0
- package/dist/modules/_old/database/model-service/dbs/hub-hackschool.db.d.ts +60 -0
- package/dist/modules/_old/database/model-service/dbs/hub-hackschool.db.js +106 -0
- package/dist/modules/_old/database/model-service/dbs/hub-newsroom.db.d.ts +25 -0
- package/dist/modules/_old/database/model-service/dbs/hub-newsroom.db.js +53 -0
- package/dist/modules/_old/database/model-service/dbs/hub-podcasts.db.d.ts +23 -0
- package/dist/modules/_old/database/model-service/dbs/hub-podcasts.db.js +45 -0
- package/dist/modules/_old/database/model-service/dbs/hub-team.db.d.ts +22 -0
- package/dist/modules/_old/database/model-service/dbs/hub-team.db.js +41 -0
- package/dist/modules/_old/database/model-service/dbs/hub-tech-radar.db.d.ts +42 -0
- package/dist/modules/_old/database/model-service/dbs/hub-tech-radar.db.js +81 -0
- package/dist/modules/_old/database/model-service/model.service.d.ts +8465 -0
- package/dist/modules/_old/database/model-service/model.service.js +136 -0
- package/dist/modules/_old/database/populate-service/populate.service.d.ts +73 -0
- package/dist/modules/_old/database/populate-service/populate.service.js +163 -0
- package/dist/modules/_old/database/service-mapper-service/service-mapper.service.d.ts +32 -0
- package/dist/modules/_old/database/service-mapper-service/service-mapper.service.js +73 -0
- package/dist/modules/_old/fetch/fetch.module.d.ts +31 -0
- package/dist/modules/_old/fetch/fetch.module.js +60 -0
- package/dist/modules/_old/fetch/fetch.service.d.ts +153 -0
- package/dist/modules/_old/fetch/fetch.service.js +274 -0
- package/dist/modules/_old/fetch/index.d.ts +2 -0
- package/dist/modules/_old/fetch/index.js +7 -0
- package/dist/modules/_old/index.d.ts +5 -0
- package/dist/modules/{comment → _old}/index.js +5 -2
- package/dist/modules/_old/like/index.d.ts +1 -0
- package/dist/modules/_old/like/index.js +5 -0
- package/dist/modules/_old/like/like.controller.d.ts +41 -0
- package/dist/modules/_old/like/like.controller.js +125 -0
- package/dist/modules/_old/like/like.module-definition.d.ts +20 -0
- package/dist/modules/_old/like/like.module-definition.js +8 -0
- package/dist/modules/_old/like/like.module.d.ts +21 -0
- package/dist/modules/_old/like/like.module.js +67 -0
- package/dist/modules/_old/like/like.service.d.ts +61 -0
- package/dist/modules/_old/like/like.service.js +103 -0
- package/dist/modules/authentication/guards/jwt-auth.guard.d.ts +1 -1
- package/dist/modules/authentication/guards/jwt-auth.guard.js +5 -3
- package/dist/modules/authentication/guards/permissions.guard.d.ts +1 -3
- package/dist/modules/authentication/guards/permissions.guard.js +2 -8
- package/dist/modules/authentication/guards/service-auth.guard.d.ts +0 -4
- package/dist/modules/authentication/guards/service-auth.guard.js +10 -13
- package/dist/modules/{comment/comment-module-options.interface.d.ts → comments/comments-module-options.interface.d.ts} +3 -2
- package/dist/modules/comments/comments-module-options.interface.js +2 -0
- package/dist/modules/{comment/comment.controller.d.ts → comments/comments.controller.d.ts} +7 -6
- package/dist/modules/{comment/comment.controller.js → comments/comments.controller.js} +14 -14
- package/dist/modules/comments/comments.module-definition.d.ts +4 -0
- package/dist/modules/comments/comments.module-definition.js +7 -0
- package/dist/modules/{comment/comment.module.d.ts → comments/comments.module.d.ts} +6 -6
- package/dist/modules/{comment/comment.module.js → comments/comments.module.js} +17 -16
- package/dist/modules/{comment/comment.service.d.ts → comments/comments.service.d.ts} +35 -9
- package/dist/modules/comments/comments.service.js +165 -0
- package/dist/modules/comments/index.d.ts +3 -0
- package/dist/modules/{services/providers/comments → comments}/index.js +2 -0
- package/dist/modules/index.d.ts +1 -1
- package/dist/modules/index.js +1 -1
- package/dist/modules/like/like-module-options.interface.d.ts +1 -0
- package/dist/modules/like/like.controller.d.ts +3 -2
- package/dist/modules/like/like.controller.js +4 -4
- package/dist/modules/like/like.module.js +1 -1
- package/dist/modules/like/like.service.d.ts +0 -16
- package/dist/modules/like/like.service.js +9 -28
- package/dist/modules/merge/merge-module-options.interface.d.ts +1 -0
- package/dist/modules/merge/merge.controller.d.ts +3 -2
- package/dist/modules/merge/merge.controller.js +4 -4
- package/dist/modules/merge/merge.module.js +1 -1
- package/dist/modules/services/providers/accounts.service.js +4 -0
- package/dist/modules/services/providers/index.d.ts +0 -1
- package/dist/modules/services/providers/index.js +0 -1
- package/dist/modules/services/services.module.js +0 -1
- package/dist/pipes/index.d.ts +1 -0
- package/dist/pipes/index.js +1 -0
- package/dist/pipes/restricted-fields.pipe.d.ts +35 -0
- package/dist/pipes/restricted-fields.pipe.js +83 -0
- package/dist/properties/content-return-type.property.d.ts +4 -0
- package/dist/properties/content-return-type.property.js +12 -7
- package/dist/properties/content.property.d.ts +7 -2
- package/dist/properties/content.property.js +11 -3
- package/dist/properties/index.d.ts +2 -4
- package/dist/properties/index.js +5 -5
- package/dist/transform/index.d.ts +2 -0
- package/dist/transform/index.js +2 -0
- package/dist/transform/mongo-id.transform.d.ts +4 -0
- package/dist/transform/mongo-id.transform.js +13 -0
- package/dist/transform/mongo-ids.transform.d.ts +4 -0
- package/dist/transform/mongo-ids.transform.js +16 -0
- package/dist/types/duplicable-model.type.d.ts +10 -0
- package/dist/types/duplicable-model.type.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/likeable.type.d.ts +4 -3
- package/dist/types/viewable.type.d.ts +4 -3
- package/dist/viewable.interface.d.ts +42 -0
- package/dist/viewable.interface.js +48 -0
- package/package.json +1 -1
- package/dist/classes/schema-builder.class.d.ts +0 -75
- package/dist/classes/schema-builder.class.js +0 -109
- package/dist/modules/comment/comment.module-definition.d.ts +0 -4
- package/dist/modules/comment/comment.service.js +0 -99
- package/dist/modules/comment/index.d.ts +0 -2
- package/dist/modules/services/providers/comments/comments.service-definition.d.ts +0 -1
- package/dist/modules/services/providers/comments/comments.service-definition.js +0 -4
- package/dist/modules/services/providers/comments/comments.service.d.ts +0 -60
- package/dist/modules/services/providers/comments/comments.service.js +0 -139
- package/dist/modules/services/providers/comments/index.d.ts +0 -1
- package/dist/properties/likeable.properties.d.ts +0 -1
- package/dist/properties/likeable.properties.js +0 -66
- package/dist/properties/viewable.properties.d.ts +0 -1
- package/dist/properties/viewable.properties.js +0 -66
- /package/dist/modules/{comment/comment-module-options.interface.js → _old/database/database-module-options.interface.js} +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Document } from 'mongoose';
|
|
2
|
+
import { User } from '../../models';
|
|
3
|
+
export declare function LikeableDocument<TBase extends new (...args: any[]) => Document>(Base: TBase): {
|
|
4
|
+
new (...args: any[]): {
|
|
5
|
+
_likedBy: string[];
|
|
6
|
+
likes: number;
|
|
7
|
+
likedBy?: User[];
|
|
8
|
+
hasLiked(accountId: string): boolean;
|
|
9
|
+
addLike(accountId: string): Promise<number>;
|
|
10
|
+
removeLike(accountId: string): Promise<number>;
|
|
11
|
+
_id: unknown;
|
|
12
|
+
$assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
|
|
13
|
+
$clearModifiedPaths(): /*elided*/ any;
|
|
14
|
+
$clone(): /*elided*/ any;
|
|
15
|
+
$createModifiedPathsSnapshot(): import("mongoose").ModifiedPathsSnapshot;
|
|
16
|
+
$getAllSubdocs(): Document[];
|
|
17
|
+
$ignore(path: string): void;
|
|
18
|
+
$isDefault(path?: string): boolean;
|
|
19
|
+
$isDeleted(val?: boolean): boolean;
|
|
20
|
+
$getPopulatedDocs(): Document[];
|
|
21
|
+
$inc(path: string | string[], val?: number): /*elided*/ any;
|
|
22
|
+
$isEmpty(path: string): boolean;
|
|
23
|
+
$isValid(path: string): boolean;
|
|
24
|
+
$locals: Record<string, unknown>;
|
|
25
|
+
$markValid(path: string): void;
|
|
26
|
+
$model<ModelType = import("mongoose").Model<unknown, {}, {}, {}, Document<unknown, {}, unknown, {}, {}> & Required<{
|
|
27
|
+
_id: unknown;
|
|
28
|
+
}> & {
|
|
29
|
+
__v: number;
|
|
30
|
+
}, any>>(name: string): ModelType;
|
|
31
|
+
$model<ModelType = import("mongoose").Model<any, {}, {}, {}, any, any>>(): ModelType;
|
|
32
|
+
$op: "save" | "validate" | "remove" | null;
|
|
33
|
+
$restoreModifiedPathsSnapshot(snapshot: import("mongoose").ModifiedPathsSnapshot): /*elided*/ any;
|
|
34
|
+
$session(session?: import("mongoose").ClientSession | null): import("mongoose").ClientSession | null;
|
|
35
|
+
$set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
36
|
+
$set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
37
|
+
$set(value: string | Record<string, any>): /*elided*/ any;
|
|
38
|
+
$where: Record<string, unknown>;
|
|
39
|
+
baseModelName?: string;
|
|
40
|
+
collection: import("mongoose").Collection;
|
|
41
|
+
db: import("mongoose").Connection;
|
|
42
|
+
deleteOne(options?: import("mongoose").QueryOptions): any;
|
|
43
|
+
depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
|
|
44
|
+
directModifiedPaths(): Array<string>;
|
|
45
|
+
equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
|
|
46
|
+
errors?: import("mongoose").Error.ValidationError;
|
|
47
|
+
get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
|
|
48
|
+
get(path: string, type?: any, options?: any): any;
|
|
49
|
+
getChanges(): import("mongoose").UpdateQuery</*elided*/ any>;
|
|
50
|
+
id?: any;
|
|
51
|
+
increment(): /*elided*/ any;
|
|
52
|
+
init(obj: import("mongoose").AnyObject, opts?: import("mongoose").AnyObject): /*elided*/ any;
|
|
53
|
+
invalidate<T extends string | number | symbol>(path: T, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
|
|
54
|
+
invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
|
|
55
|
+
isDirectModified<T extends string | number | symbol>(path: T | T[]): boolean;
|
|
56
|
+
isDirectModified(path: string | Array<string>): boolean;
|
|
57
|
+
isDirectSelected<T extends string | number | symbol>(path: T): boolean;
|
|
58
|
+
isDirectSelected(path: string): boolean;
|
|
59
|
+
isInit<T extends string | number | symbol>(path: T): boolean;
|
|
60
|
+
isInit(path: string): boolean;
|
|
61
|
+
isModified<T extends string | number | symbol>(path?: T | T[], options?: {
|
|
62
|
+
ignoreAtomics?: boolean;
|
|
63
|
+
} | null): boolean;
|
|
64
|
+
isModified(path?: string | Array<string>, options?: {
|
|
65
|
+
ignoreAtomics?: boolean;
|
|
66
|
+
} | null): boolean;
|
|
67
|
+
isNew: boolean;
|
|
68
|
+
isSelected<T extends string | number | symbol>(path: T): boolean;
|
|
69
|
+
isSelected(path: string): boolean;
|
|
70
|
+
markModified<T extends string | number | symbol>(path: T, scope?: any): void;
|
|
71
|
+
markModified(path: string, scope?: any): void;
|
|
72
|
+
model<ModelType = import("mongoose").Model<unknown, {}, {}, {}, Document<unknown, {}, unknown, {}, {}> & Required<{
|
|
73
|
+
_id: unknown;
|
|
74
|
+
}> & {
|
|
75
|
+
__v: number;
|
|
76
|
+
}, any>>(name: string): ModelType;
|
|
77
|
+
model<ModelType = import("mongoose").Model<any, {}, {}, {}, any, any>>(): ModelType;
|
|
78
|
+
modifiedPaths(options?: {
|
|
79
|
+
includeChildren?: boolean;
|
|
80
|
+
}): Array<string>;
|
|
81
|
+
overwrite(obj: import("mongoose").AnyObject): /*elided*/ any;
|
|
82
|
+
$parent(): Document | undefined;
|
|
83
|
+
populate<Paths = {}>(path: string | import("mongoose").PopulateOptions | (string | import("mongoose").PopulateOptions)[]): Promise<import("mongoose").MergeType</*elided*/ any, Paths>>;
|
|
84
|
+
populate<Paths = {}>(path: string, select?: string | import("mongoose").AnyObject, model?: import("mongoose").Model<any>, match?: import("mongoose").AnyObject, options?: import("mongoose").PopulateOptions): Promise<import("mongoose").MergeType</*elided*/ any, Paths>>;
|
|
85
|
+
populated(path: string): any;
|
|
86
|
+
replaceOne(replacement?: import("mongoose").AnyObject, options?: import("mongoose").QueryOptions | null): import("mongoose").Query<any, /*elided*/ any, {}, unknown, "find", Record<string, never>>;
|
|
87
|
+
save(options?: import("mongoose").SaveOptions): Promise</*elided*/ any>;
|
|
88
|
+
schema: import("mongoose").Schema;
|
|
89
|
+
set<T extends string | number | symbol>(path: T, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
90
|
+
set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
91
|
+
set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
92
|
+
set(value: string | Record<string, any>): /*elided*/ any;
|
|
93
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
94
|
+
versionKey: false;
|
|
95
|
+
virtuals: true;
|
|
96
|
+
flattenObjectIds: true;
|
|
97
|
+
}): Omit<{
|
|
98
|
+
[x: string]: any;
|
|
99
|
+
}, "__v">;
|
|
100
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
101
|
+
virtuals: true;
|
|
102
|
+
flattenObjectIds: true;
|
|
103
|
+
}): {
|
|
104
|
+
[x: string]: any;
|
|
105
|
+
};
|
|
106
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
107
|
+
versionKey: false;
|
|
108
|
+
virtuals: true;
|
|
109
|
+
}): Omit<any, "__v">;
|
|
110
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
111
|
+
versionKey: false;
|
|
112
|
+
flattenObjectIds: true;
|
|
113
|
+
}): {
|
|
114
|
+
[x: string]: any;
|
|
115
|
+
[x: number]: any;
|
|
116
|
+
[x: symbol]: any;
|
|
117
|
+
};
|
|
118
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
119
|
+
virtuals: true;
|
|
120
|
+
}): any;
|
|
121
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
122
|
+
versionKey: false;
|
|
123
|
+
}): Omit<any, "__v">;
|
|
124
|
+
toJSON(options?: import("mongoose").ToObjectOptions & {
|
|
125
|
+
flattenMaps?: true;
|
|
126
|
+
flattenObjectIds?: false;
|
|
127
|
+
}): import("mongoose").FlattenMaps<any>;
|
|
128
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
129
|
+
flattenObjectIds: false;
|
|
130
|
+
}): import("mongoose").FlattenMaps<any>;
|
|
131
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
132
|
+
flattenObjectIds: true;
|
|
133
|
+
}): {
|
|
134
|
+
[x: string]: any;
|
|
135
|
+
};
|
|
136
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
137
|
+
flattenMaps: false;
|
|
138
|
+
}): any;
|
|
139
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
140
|
+
flattenMaps: false;
|
|
141
|
+
flattenObjectIds: true;
|
|
142
|
+
}): any;
|
|
143
|
+
toJSON<T = any>(options?: import("mongoose").ToObjectOptions & {
|
|
144
|
+
flattenMaps?: true;
|
|
145
|
+
flattenObjectIds?: false;
|
|
146
|
+
}): import("mongoose").FlattenMaps<T>;
|
|
147
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
148
|
+
flattenObjectIds: false;
|
|
149
|
+
}): import("mongoose").FlattenMaps<T>;
|
|
150
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
151
|
+
flattenObjectIds: true;
|
|
152
|
+
}): import("mongoose").ObjectIdToString<import("mongoose").FlattenMaps<T>>;
|
|
153
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
154
|
+
flattenMaps: false;
|
|
155
|
+
}): T;
|
|
156
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
157
|
+
flattenMaps: false;
|
|
158
|
+
flattenObjectIds: true;
|
|
159
|
+
}): import("mongoose").ObjectIdToString<T>;
|
|
160
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
161
|
+
versionKey: false;
|
|
162
|
+
virtuals: true;
|
|
163
|
+
flattenObjectIds: true;
|
|
164
|
+
}): Omit<any, "__v">;
|
|
165
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
166
|
+
virtuals: true;
|
|
167
|
+
flattenObjectIds: true;
|
|
168
|
+
}): any;
|
|
169
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
170
|
+
versionKey: false;
|
|
171
|
+
flattenObjectIds: true;
|
|
172
|
+
}): Omit<any, "__v">;
|
|
173
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
174
|
+
versionKey: false;
|
|
175
|
+
virtuals: true;
|
|
176
|
+
}): Omit<any, "__v">;
|
|
177
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
178
|
+
virtuals: true;
|
|
179
|
+
}): any;
|
|
180
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
181
|
+
versionKey: false;
|
|
182
|
+
}): Omit<any, "__v">;
|
|
183
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
184
|
+
flattenObjectIds: true;
|
|
185
|
+
}): any;
|
|
186
|
+
toObject(options?: import("mongoose").ToObjectOptions): any;
|
|
187
|
+
toObject<T>(options?: import("mongoose").ToObjectOptions): import("mongoose").Require_id<T> & {
|
|
188
|
+
__v: number;
|
|
189
|
+
};
|
|
190
|
+
unmarkModified<T extends string | number | symbol>(path: T): void;
|
|
191
|
+
unmarkModified(path: string): void;
|
|
192
|
+
updateOne(update?: import("mongoose").UpdateWithAggregationPipeline | import("mongoose").UpdateQuery</*elided*/ any>, options?: import("mongoose").QueryOptions | null): import("mongoose").Query<any, /*elided*/ any, {}, unknown, "find", Record<string, never>>;
|
|
193
|
+
validate<T extends string | number | symbol>(pathsToValidate?: T | T[], options?: import("mongoose").AnyObject): Promise<void>;
|
|
194
|
+
validate(pathsToValidate?: import("mongoose").pathsToValidate, options?: import("mongoose").AnyObject): Promise<void>;
|
|
195
|
+
validate(options: {
|
|
196
|
+
pathsToSkip?: import("mongoose").pathsToSkip;
|
|
197
|
+
}): Promise<void>;
|
|
198
|
+
validateSync(options: {
|
|
199
|
+
pathsToSkip?: import("mongoose").pathsToSkip;
|
|
200
|
+
[k: string]: any;
|
|
201
|
+
}): import("mongoose").Error.ValidationError | null;
|
|
202
|
+
validateSync<T extends string | number | symbol>(pathsToValidate?: T | T[], options?: import("mongoose").AnyObject): import("mongoose").Error.ValidationError | null;
|
|
203
|
+
validateSync(pathsToValidate?: import("mongoose").pathsToValidate, options?: import("mongoose").AnyObject): import("mongoose").Error.ValidationError | null;
|
|
204
|
+
};
|
|
205
|
+
} & TBase;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LikeableDocument = LikeableDocument;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const class_validator_1 = require("class-validator");
|
|
16
|
+
const models_1 = require("../../models");
|
|
17
|
+
function LikeableDocument(Base) {
|
|
18
|
+
class LikeableDocument extends Base {
|
|
19
|
+
hasLiked(accountId) {
|
|
20
|
+
return this._likedBy.includes(accountId);
|
|
21
|
+
}
|
|
22
|
+
async addLike(accountId) {
|
|
23
|
+
if (!(0, class_validator_1.isMongoId)(accountId))
|
|
24
|
+
return this.likes;
|
|
25
|
+
this._likedBy = Array.from(new Set([...this._likedBy, accountId]));
|
|
26
|
+
this.likes = this._likedBy.length;
|
|
27
|
+
await this.save({ timestamps: false });
|
|
28
|
+
return this.likes;
|
|
29
|
+
}
|
|
30
|
+
async removeLike(accountId) {
|
|
31
|
+
if (!(0, class_validator_1.isMongoId)(accountId))
|
|
32
|
+
return this.likes;
|
|
33
|
+
this._likedBy = this._likedBy.filter((id) => id !== accountId);
|
|
34
|
+
this.likes = this._likedBy.length;
|
|
35
|
+
await this.save({ timestamps: false });
|
|
36
|
+
return this.likes;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
41
|
+
name: '_likedBy',
|
|
42
|
+
description: 'Array of user IDs that liked this resource.',
|
|
43
|
+
type: [String],
|
|
44
|
+
default: [],
|
|
45
|
+
}),
|
|
46
|
+
(0, mongoose_1.Prop)({ type: [String], default: [] }),
|
|
47
|
+
__metadata("design:type", Array)
|
|
48
|
+
], LikeableDocument.prototype, "_likedBy", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
51
|
+
name: 'likes',
|
|
52
|
+
description: 'Total number of likes for this resource.',
|
|
53
|
+
type: Number,
|
|
54
|
+
default: 0,
|
|
55
|
+
}),
|
|
56
|
+
(0, mongoose_1.Prop)({ type: Number, default: 0 }),
|
|
57
|
+
__metadata("design:type", Number)
|
|
58
|
+
], LikeableDocument.prototype, "likes", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
61
|
+
name: 'likedBy',
|
|
62
|
+
description: 'Populated list of User objects who liked this resource.',
|
|
63
|
+
type: [models_1.User],
|
|
64
|
+
default: [],
|
|
65
|
+
}),
|
|
66
|
+
(0, mongoose_1.Virtual)(),
|
|
67
|
+
__metadata("design:type", Array)
|
|
68
|
+
], LikeableDocument.prototype, "likedBy", void 0);
|
|
69
|
+
return LikeableDocument;
|
|
70
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Document } from 'mongoose';
|
|
2
|
+
import { User } from '../../models';
|
|
3
|
+
export declare function ViewableDocument<TBase extends new (...args: any[]) => Document>(Base: TBase): {
|
|
4
|
+
new (...args: any[]): {
|
|
5
|
+
_viewedBy: string[];
|
|
6
|
+
views: number;
|
|
7
|
+
viewedBy?: User[];
|
|
8
|
+
hasViewed(accountId: string): boolean;
|
|
9
|
+
addView(accountId: string): Promise<number>;
|
|
10
|
+
removeView(accountId: string): Promise<number>;
|
|
11
|
+
_id: unknown;
|
|
12
|
+
$assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
|
|
13
|
+
$clearModifiedPaths(): /*elided*/ any;
|
|
14
|
+
$clone(): /*elided*/ any;
|
|
15
|
+
$createModifiedPathsSnapshot(): import("mongoose").ModifiedPathsSnapshot;
|
|
16
|
+
$getAllSubdocs(): Document[];
|
|
17
|
+
$ignore(path: string): void;
|
|
18
|
+
$isDefault(path?: string): boolean;
|
|
19
|
+
$isDeleted(val?: boolean): boolean;
|
|
20
|
+
$getPopulatedDocs(): Document[];
|
|
21
|
+
$inc(path: string | string[], val?: number): /*elided*/ any;
|
|
22
|
+
$isEmpty(path: string): boolean;
|
|
23
|
+
$isValid(path: string): boolean;
|
|
24
|
+
$locals: Record<string, unknown>;
|
|
25
|
+
$markValid(path: string): void;
|
|
26
|
+
$model<ModelType = import("mongoose").Model<unknown, {}, {}, {}, Document<unknown, {}, unknown, {}, {}> & Required<{
|
|
27
|
+
_id: unknown;
|
|
28
|
+
}> & {
|
|
29
|
+
__v: number;
|
|
30
|
+
}, any>>(name: string): ModelType;
|
|
31
|
+
$model<ModelType = import("mongoose").Model<any, {}, {}, {}, any, any>>(): ModelType;
|
|
32
|
+
$op: "save" | "validate" | "remove" | null;
|
|
33
|
+
$restoreModifiedPathsSnapshot(snapshot: import("mongoose").ModifiedPathsSnapshot): /*elided*/ any;
|
|
34
|
+
$session(session?: import("mongoose").ClientSession | null): import("mongoose").ClientSession | null;
|
|
35
|
+
$set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
36
|
+
$set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
37
|
+
$set(value: string | Record<string, any>): /*elided*/ any;
|
|
38
|
+
$where: Record<string, unknown>;
|
|
39
|
+
baseModelName?: string;
|
|
40
|
+
collection: import("mongoose").Collection;
|
|
41
|
+
db: import("mongoose").Connection;
|
|
42
|
+
deleteOne(options?: import("mongoose").QueryOptions): any;
|
|
43
|
+
depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
|
|
44
|
+
directModifiedPaths(): Array<string>;
|
|
45
|
+
equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
|
|
46
|
+
errors?: import("mongoose").Error.ValidationError;
|
|
47
|
+
get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
|
|
48
|
+
get(path: string, type?: any, options?: any): any;
|
|
49
|
+
getChanges(): import("mongoose").UpdateQuery</*elided*/ any>;
|
|
50
|
+
id?: any;
|
|
51
|
+
increment(): /*elided*/ any;
|
|
52
|
+
init(obj: import("mongoose").AnyObject, opts?: import("mongoose").AnyObject): /*elided*/ any;
|
|
53
|
+
invalidate<T extends string | number | symbol>(path: T, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
|
|
54
|
+
invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
|
|
55
|
+
isDirectModified<T extends string | number | symbol>(path: T | T[]): boolean;
|
|
56
|
+
isDirectModified(path: string | Array<string>): boolean;
|
|
57
|
+
isDirectSelected<T extends string | number | symbol>(path: T): boolean;
|
|
58
|
+
isDirectSelected(path: string): boolean;
|
|
59
|
+
isInit<T extends string | number | symbol>(path: T): boolean;
|
|
60
|
+
isInit(path: string): boolean;
|
|
61
|
+
isModified<T extends string | number | symbol>(path?: T | T[], options?: {
|
|
62
|
+
ignoreAtomics?: boolean;
|
|
63
|
+
} | null): boolean;
|
|
64
|
+
isModified(path?: string | Array<string>, options?: {
|
|
65
|
+
ignoreAtomics?: boolean;
|
|
66
|
+
} | null): boolean;
|
|
67
|
+
isNew: boolean;
|
|
68
|
+
isSelected<T extends string | number | symbol>(path: T): boolean;
|
|
69
|
+
isSelected(path: string): boolean;
|
|
70
|
+
markModified<T extends string | number | symbol>(path: T, scope?: any): void;
|
|
71
|
+
markModified(path: string, scope?: any): void;
|
|
72
|
+
model<ModelType = import("mongoose").Model<unknown, {}, {}, {}, Document<unknown, {}, unknown, {}, {}> & Required<{
|
|
73
|
+
_id: unknown;
|
|
74
|
+
}> & {
|
|
75
|
+
__v: number;
|
|
76
|
+
}, any>>(name: string): ModelType;
|
|
77
|
+
model<ModelType = import("mongoose").Model<any, {}, {}, {}, any, any>>(): ModelType;
|
|
78
|
+
modifiedPaths(options?: {
|
|
79
|
+
includeChildren?: boolean;
|
|
80
|
+
}): Array<string>;
|
|
81
|
+
overwrite(obj: import("mongoose").AnyObject): /*elided*/ any;
|
|
82
|
+
$parent(): Document | undefined;
|
|
83
|
+
populate<Paths = {}>(path: string | import("mongoose").PopulateOptions | (string | import("mongoose").PopulateOptions)[]): Promise<import("mongoose").MergeType</*elided*/ any, Paths>>;
|
|
84
|
+
populate<Paths = {}>(path: string, select?: string | import("mongoose").AnyObject, model?: import("mongoose").Model<any>, match?: import("mongoose").AnyObject, options?: import("mongoose").PopulateOptions): Promise<import("mongoose").MergeType</*elided*/ any, Paths>>;
|
|
85
|
+
populated(path: string): any;
|
|
86
|
+
replaceOne(replacement?: import("mongoose").AnyObject, options?: import("mongoose").QueryOptions | null): import("mongoose").Query<any, /*elided*/ any, {}, unknown, "find", Record<string, never>>;
|
|
87
|
+
save(options?: import("mongoose").SaveOptions): Promise</*elided*/ any>;
|
|
88
|
+
schema: import("mongoose").Schema;
|
|
89
|
+
set<T extends string | number | symbol>(path: T, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
90
|
+
set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
91
|
+
set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
|
|
92
|
+
set(value: string | Record<string, any>): /*elided*/ any;
|
|
93
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
94
|
+
versionKey: false;
|
|
95
|
+
virtuals: true;
|
|
96
|
+
flattenObjectIds: true;
|
|
97
|
+
}): Omit<{
|
|
98
|
+
[x: string]: any;
|
|
99
|
+
}, "__v">;
|
|
100
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
101
|
+
virtuals: true;
|
|
102
|
+
flattenObjectIds: true;
|
|
103
|
+
}): {
|
|
104
|
+
[x: string]: any;
|
|
105
|
+
};
|
|
106
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
107
|
+
versionKey: false;
|
|
108
|
+
virtuals: true;
|
|
109
|
+
}): Omit<any, "__v">;
|
|
110
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
111
|
+
versionKey: false;
|
|
112
|
+
flattenObjectIds: true;
|
|
113
|
+
}): {
|
|
114
|
+
[x: string]: any;
|
|
115
|
+
[x: number]: any;
|
|
116
|
+
[x: symbol]: any;
|
|
117
|
+
};
|
|
118
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
119
|
+
virtuals: true;
|
|
120
|
+
}): any;
|
|
121
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
122
|
+
versionKey: false;
|
|
123
|
+
}): Omit<any, "__v">;
|
|
124
|
+
toJSON(options?: import("mongoose").ToObjectOptions & {
|
|
125
|
+
flattenMaps?: true;
|
|
126
|
+
flattenObjectIds?: false;
|
|
127
|
+
}): import("mongoose").FlattenMaps<any>;
|
|
128
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
129
|
+
flattenObjectIds: false;
|
|
130
|
+
}): import("mongoose").FlattenMaps<any>;
|
|
131
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
132
|
+
flattenObjectIds: true;
|
|
133
|
+
}): {
|
|
134
|
+
[x: string]: any;
|
|
135
|
+
};
|
|
136
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
137
|
+
flattenMaps: false;
|
|
138
|
+
}): any;
|
|
139
|
+
toJSON(options: import("mongoose").ToObjectOptions & {
|
|
140
|
+
flattenMaps: false;
|
|
141
|
+
flattenObjectIds: true;
|
|
142
|
+
}): any;
|
|
143
|
+
toJSON<T = any>(options?: import("mongoose").ToObjectOptions & {
|
|
144
|
+
flattenMaps?: true;
|
|
145
|
+
flattenObjectIds?: false;
|
|
146
|
+
}): import("mongoose").FlattenMaps<T>;
|
|
147
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
148
|
+
flattenObjectIds: false;
|
|
149
|
+
}): import("mongoose").FlattenMaps<T>;
|
|
150
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
151
|
+
flattenObjectIds: true;
|
|
152
|
+
}): import("mongoose").ObjectIdToString<import("mongoose").FlattenMaps<T>>;
|
|
153
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
154
|
+
flattenMaps: false;
|
|
155
|
+
}): T;
|
|
156
|
+
toJSON<T = any>(options: import("mongoose").ToObjectOptions & {
|
|
157
|
+
flattenMaps: false;
|
|
158
|
+
flattenObjectIds: true;
|
|
159
|
+
}): import("mongoose").ObjectIdToString<T>;
|
|
160
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
161
|
+
versionKey: false;
|
|
162
|
+
virtuals: true;
|
|
163
|
+
flattenObjectIds: true;
|
|
164
|
+
}): Omit<any, "__v">;
|
|
165
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
166
|
+
virtuals: true;
|
|
167
|
+
flattenObjectIds: true;
|
|
168
|
+
}): any;
|
|
169
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
170
|
+
versionKey: false;
|
|
171
|
+
flattenObjectIds: true;
|
|
172
|
+
}): Omit<any, "__v">;
|
|
173
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
174
|
+
versionKey: false;
|
|
175
|
+
virtuals: true;
|
|
176
|
+
}): Omit<any, "__v">;
|
|
177
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
178
|
+
virtuals: true;
|
|
179
|
+
}): any;
|
|
180
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
181
|
+
versionKey: false;
|
|
182
|
+
}): Omit<any, "__v">;
|
|
183
|
+
toObject(options: import("mongoose").ToObjectOptions & {
|
|
184
|
+
flattenObjectIds: true;
|
|
185
|
+
}): any;
|
|
186
|
+
toObject(options?: import("mongoose").ToObjectOptions): any;
|
|
187
|
+
toObject<T>(options?: import("mongoose").ToObjectOptions): import("mongoose").Require_id<T> & {
|
|
188
|
+
__v: number;
|
|
189
|
+
};
|
|
190
|
+
unmarkModified<T extends string | number | symbol>(path: T): void;
|
|
191
|
+
unmarkModified(path: string): void;
|
|
192
|
+
updateOne(update?: import("mongoose").UpdateWithAggregationPipeline | import("mongoose").UpdateQuery</*elided*/ any>, options?: import("mongoose").QueryOptions | null): import("mongoose").Query<any, /*elided*/ any, {}, unknown, "find", Record<string, never>>;
|
|
193
|
+
validate<T extends string | number | symbol>(pathsToValidate?: T | T[], options?: import("mongoose").AnyObject): Promise<void>;
|
|
194
|
+
validate(pathsToValidate?: import("mongoose").pathsToValidate, options?: import("mongoose").AnyObject): Promise<void>;
|
|
195
|
+
validate(options: {
|
|
196
|
+
pathsToSkip?: import("mongoose").pathsToSkip;
|
|
197
|
+
}): Promise<void>;
|
|
198
|
+
validateSync(options: {
|
|
199
|
+
pathsToSkip?: import("mongoose").pathsToSkip;
|
|
200
|
+
[k: string]: any;
|
|
201
|
+
}): import("mongoose").Error.ValidationError | null;
|
|
202
|
+
validateSync<T extends string | number | symbol>(pathsToValidate?: T | T[], options?: import("mongoose").AnyObject): import("mongoose").Error.ValidationError | null;
|
|
203
|
+
validateSync(pathsToValidate?: import("mongoose").pathsToValidate, options?: import("mongoose").AnyObject): import("mongoose").Error.ValidationError | null;
|
|
204
|
+
};
|
|
205
|
+
} & TBase;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ViewableDocument = ViewableDocument;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const class_validator_1 = require("class-validator");
|
|
16
|
+
const models_1 = require("../../models");
|
|
17
|
+
function ViewableDocument(Base) {
|
|
18
|
+
class ViewableDocument extends Base {
|
|
19
|
+
hasViewed(accountId) {
|
|
20
|
+
return this._viewedBy.includes(accountId);
|
|
21
|
+
}
|
|
22
|
+
async addView(accountId) {
|
|
23
|
+
if (!(0, class_validator_1.isMongoId)(accountId))
|
|
24
|
+
return this.views;
|
|
25
|
+
this._viewedBy = Array.from(new Set([...this._viewedBy, accountId]));
|
|
26
|
+
this.views = this._viewedBy.length;
|
|
27
|
+
await this.save({ timestamps: false });
|
|
28
|
+
return this.views;
|
|
29
|
+
}
|
|
30
|
+
async removeView(accountId) {
|
|
31
|
+
if (!(0, class_validator_1.isMongoId)(accountId))
|
|
32
|
+
return this.views;
|
|
33
|
+
this._viewedBy = this._viewedBy.filter((id) => id !== accountId);
|
|
34
|
+
this.views = this._viewedBy.length;
|
|
35
|
+
await this.save({ timestamps: false });
|
|
36
|
+
return this.views;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
41
|
+
description: 'Array of user IDs that have viewed this resource.',
|
|
42
|
+
type: [String],
|
|
43
|
+
default: [],
|
|
44
|
+
}),
|
|
45
|
+
(0, mongoose_1.Prop)({ type: [String], default: [] }),
|
|
46
|
+
__metadata("design:type", Array)
|
|
47
|
+
], ViewableDocument.prototype, "_viewedBy", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
50
|
+
description: 'Total number of views for this resource.',
|
|
51
|
+
type: Number,
|
|
52
|
+
default: 0,
|
|
53
|
+
}),
|
|
54
|
+
(0, mongoose_1.Prop)({ type: Number, default: 0 }),
|
|
55
|
+
__metadata("design:type", Number)
|
|
56
|
+
], ViewableDocument.prototype, "views", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
59
|
+
description: 'Populated list of User objects who viewed this resource.',
|
|
60
|
+
type: [models_1.User],
|
|
61
|
+
default: [],
|
|
62
|
+
}),
|
|
63
|
+
(0, mongoose_1.Virtual)(),
|
|
64
|
+
__metadata("design:type", Array)
|
|
65
|
+
], ViewableDocument.prototype, "viewedBy", void 0);
|
|
66
|
+
return ViewableDocument;
|
|
67
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Document } from 'mongoose';
|
|
2
|
+
import { Viewable } from '../viewable.interface';
|
|
3
|
+
/**
|
|
4
|
+
* TODO: REMOVE
|
|
5
|
+
* Facilitates asynchronous updates to documents by adding unique account IDs to specified
|
|
6
|
+
* array attributes. This prevents duplication of IDs in those arrays, ensuring data integrity.
|
|
7
|
+
*
|
|
8
|
+
* Designed primarily for adding account references such as views or other related IDs.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DocumentUpdater {
|
|
11
|
+
private static readonly logger;
|
|
12
|
+
/**
|
|
13
|
+
* Adds an account ID uniquely to a specified array attribute of a document.
|
|
14
|
+
*
|
|
15
|
+
* This method verifies the presence of an accountId before proceeding.
|
|
16
|
+
* It then performs an atomic MongoDB `$addToSet` update on the document to
|
|
17
|
+
* add the accountId to the given attribute array only if it is not already present,
|
|
18
|
+
* preventing duplicates without needing to fetch the document first.
|
|
19
|
+
*
|
|
20
|
+
* Updates are saved without modifying timestamps to preserve original metadata.
|
|
21
|
+
*
|
|
22
|
+
* @template I - Interface representing the document’s shape.
|
|
23
|
+
* @template T - Mongoose Document type extending `Document`.
|
|
24
|
+
* @param document - The Mongoose document to update.
|
|
25
|
+
* @param attribute - The document attribute (key) representing the array to update.
|
|
26
|
+
* @param accountId - The unique account ID to add.
|
|
27
|
+
*/
|
|
28
|
+
static addUniqueAccountId<I, T extends Document = Document>(document: T, attribute: keyof I, accountId?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Adds a view record to a document by associating an account ID with the '_viewedBy' attribute.
|
|
31
|
+
*
|
|
32
|
+
* This method leverages `addUniqueAccountId` to add the given accountId to the '_viewedBy' array,
|
|
33
|
+
* ensuring each viewer is recorded only once.
|
|
34
|
+
*
|
|
35
|
+
* @template T - Mongoose Document type that extends Document and implements Viewable interface.
|
|
36
|
+
* @param target - The target document to record the view.
|
|
37
|
+
* @param accountId - The account ID representing the viewer.
|
|
38
|
+
*/
|
|
39
|
+
static addView<T extends Document & Viewable>(target: T, accountId?: string): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentUpdater = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* TODO: REMOVE
|
|
7
|
+
* Facilitates asynchronous updates to documents by adding unique account IDs to specified
|
|
8
|
+
* array attributes. This prevents duplication of IDs in those arrays, ensuring data integrity.
|
|
9
|
+
*
|
|
10
|
+
* Designed primarily for adding account references such as views or other related IDs.
|
|
11
|
+
*/
|
|
12
|
+
class DocumentUpdater {
|
|
13
|
+
/**
|
|
14
|
+
* Adds an account ID uniquely to a specified array attribute of a document.
|
|
15
|
+
*
|
|
16
|
+
* This method verifies the presence of an accountId before proceeding.
|
|
17
|
+
* It then performs an atomic MongoDB `$addToSet` update on the document to
|
|
18
|
+
* add the accountId to the given attribute array only if it is not already present,
|
|
19
|
+
* preventing duplicates without needing to fetch the document first.
|
|
20
|
+
*
|
|
21
|
+
* Updates are saved without modifying timestamps to preserve original metadata.
|
|
22
|
+
*
|
|
23
|
+
* @template I - Interface representing the document’s shape.
|
|
24
|
+
* @template T - Mongoose Document type extending `Document`.
|
|
25
|
+
* @param document - The Mongoose document to update.
|
|
26
|
+
* @param attribute - The document attribute (key) representing the array to update.
|
|
27
|
+
* @param accountId - The unique account ID to add.
|
|
28
|
+
*/
|
|
29
|
+
static addUniqueAccountId(document, attribute, accountId) {
|
|
30
|
+
if (!accountId)
|
|
31
|
+
return; // Exit if no accountId provided, avoiding unnecessary operations.
|
|
32
|
+
// Perform atomic update to add accountId uniquely to the attribute array.
|
|
33
|
+
document
|
|
34
|
+
.updateOne({ $addToSet: { [String(attribute)]: accountId } }, { timestamps: false })
|
|
35
|
+
.then(() => {
|
|
36
|
+
this.logger.log(`Added unique accountId '${accountId}' to attribute '${String(attribute)}' for document ${document._id.toString()}`);
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
// Log any errors during the update operation for debugging and audit.
|
|
40
|
+
this.logger.error(`Failed to add accountId '${accountId}' to attribute '${String(attribute)}' for document ${document._id.toString()}: ${error.stack}`);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Adds a view record to a document by associating an account ID with the '_viewedBy' attribute.
|
|
45
|
+
*
|
|
46
|
+
* This method leverages `addUniqueAccountId` to add the given accountId to the '_viewedBy' array,
|
|
47
|
+
* ensuring each viewer is recorded only once.
|
|
48
|
+
*
|
|
49
|
+
* @template T - Mongoose Document type that extends Document and implements Viewable interface.
|
|
50
|
+
* @param target - The target document to record the view.
|
|
51
|
+
* @param accountId - The account ID representing the viewer.
|
|
52
|
+
*/
|
|
53
|
+
static addView(target, accountId) {
|
|
54
|
+
this.addUniqueAccountId(target, '_viewedBy', accountId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.DocumentUpdater = DocumentUpdater;
|
|
58
|
+
DocumentUpdater.logger = new common_1.Logger('DocumentUpdater');
|