Skip to content

Commit

Permalink
refactor: wrap findNotSubscribedWorkItems in repository model
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jan 13, 2024
1 parent 50935d5 commit a0b4299
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
16 changes: 2 additions & 14 deletions api/dicom-web/controller/UPS-RS/service/subscribe.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const _ = require("lodash");
const { DicomJsonModel } = require("@dicom-json-model");
const { DicomCode } = require("@models/DICOM/code");
const workItemModel = require("@models/mongodb/models/workitems.model");
const { WorkItemModel } = require("@models/mongodb/models/workitems.model");
const subscriptionModel = require("@models/mongodb/models/upsSubscription");
const globalSubscriptionModel = require("@models/mongodb/models/upsGlobalSubscription");
const {
Expand Down Expand Up @@ -154,19 +154,7 @@ class SubscribeService extends BaseWorkItemService {
//#endregion

async findNotSubscribedWorkItems() {
return await workItemModel.find({
$or: [
{
subscribed: SUBSCRIPTION_STATE.NOT_SUBSCRIBED
},
{
subscribed: {
$exists: false
}
}
]

}) || [];
return await WorkItemModel.findNotSubscribedWorkItems();
}
}

Expand Down
24 changes: 17 additions & 7 deletions models/mongodb/models/workitems.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ let workItemSchema = new mongoose.Schema(
toObject: {
getters: true
},
statics: {
findNotSubscribedWorkItems: async function () {
return await mongoose.model("workItems").find({
$or: [
{
subscribed: SUBSCRIPTION_STATE.NOT_SUBSCRIBED
},
{
subscribed: {
$exists: false
}
}
]

}) || [];
}
},
methods: {
toDicomJsonModel: function () {
return new DicomJsonModel(this);
Expand Down Expand Up @@ -110,13 +127,6 @@ function getWorkItemFields() {
};
}

/**
* @typedef { mongoose.Model<mongoose.Schema> & {
* getDicomJson: function(import("../../../utils/typeDef/dicom").DicomJsonMongoQueryOptions): Promise<function>
* }} WorkItemsModel
*/

/** @type {WorkItemsModel} */
let workItemModel = mongoose.model(
"workItems",
workItemSchema,
Expand Down

0 comments on commit a0b4299

Please sign in to comment.