From 48d047db678c1ce68f43e858ce9c3b433ddf25aa Mon Sep 17 00:00:00 2001 From: chinlinlee Date: Thu, 25 Jan 2024 17:06:42 +0800 Subject: [PATCH] docs(type): add types for `UpsGlobalSubscriptionModel` --- .../mongodb/models/upsGlobalSubscription.js | 20 +++++++++++-- .../typeDef/models/upsGlobalSubscription.d.ts | 30 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 utils/typeDef/models/upsGlobalSubscription.d.ts diff --git a/models/mongodb/models/upsGlobalSubscription.js b/models/mongodb/models/upsGlobalSubscription.js index af796b04..cf7815fc 100644 --- a/models/mongodb/models/upsGlobalSubscription.js +++ b/models/mongodb/models/upsGlobalSubscription.js @@ -33,29 +33,42 @@ let upsGlobalSubscriptionSchema = new mongoose.Schema( getters: true }, statics: { + /** + * @type {import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor["getCursor"]} + */ getCursor: async function (query, options) { return await mongoose.model("upsGlobalSubscription").find(query, options).cursor(); }, + /** + * @type { import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor["createGlobalSubscription"] } + */ createGlobalSubscription: async function (globalSubscription) { return await mongoose.model("upsGlobalSubscription").create(globalSubscription); }, + /** + * @type { import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor["updateRepositoryInstance"] } + */ updateRepositoryInstance: async function (globalSubscription, query, deletionLock, subscribed) { globalSubscription.isDeletionLock = deletionLock; globalSubscription.subscribed = subscribed; globalSubscription.queryKeys = query; return await globalSubscription.save(); }, + /** + * @type { import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor["findOneByAeTitle"] } + */ findOneByAeTitle: async function (aeTitle) { return await mongoose.model("upsGlobalSubscription").findOne({ aeTitle: aeTitle }); }, /** - * - * @param {string} aeTitle - * @returns + * @type { import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor["getCountByAeTitle"] } */ getCountByAeTitle: async function (aeTitle) { return await mongoose.model("upsGlobalSubscription").countDocuments({ aeTitle: aeTitle }); }, + /** + * @type { import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor["deleteOneByAeTitle"] } + */ deleteOneByAeTitle: async function (aeTitle) { return await mongoose.model("upsGlobalSubscription").findOneAndDelete({ aeTitle: aeTitle }); } @@ -71,4 +84,5 @@ let upsSubscriptionModel = mongoose.model( ); module.exports = upsSubscriptionModel; +/** @type { import("@root/utils/typeDef/models/upsGlobalSubscription").UpsGlobalSubscriptionConstructor } */ module.exports.UpsGlobalSubscriptionModel = upsSubscriptionModel; diff --git a/utils/typeDef/models/upsGlobalSubscription.d.ts b/utils/typeDef/models/upsGlobalSubscription.d.ts new file mode 100644 index 00000000..e1c5d408 --- /dev/null +++ b/utils/typeDef/models/upsGlobalSubscription.d.ts @@ -0,0 +1,30 @@ +export interface UpsGlobalSubscriptionConstructor { + new(): UpsGlobalSubscriptionModel; + /** + * + * @param query + * @param options + * @returns Cursor + */ + public static getCursor(query: any, options: any): Promise; + public static createGlobalSubscription( + globalSubscription: UpsGlobalSubscription + ): Promise; + public static updateRepositoryInstance( + globalSubscription: UpsGlobalSubscriptionModel + ): Promise; + public static findOneByAeTitle( + aeTitle: string + ): Promise; + public static getCountByAeTitle(aeTitle: string): Promise; + public static deleteOneByAeTitle(aeTitle: string): Promise; +} + +export type UpsGlobalSubscription = { + aeTitle: string; + subscribed: number; + queryKeys: any; + isDeletionLock: boolean; +}; + +export interface UpsGlobalSubscriptionModel {}