Skip to content

Commit b5d0a35

Browse files
authored
Merge pull request #150 from asthasingh182004/73-refractor-organization-model
73 refractor organization model
2 parents 24cb4ef + c446336 commit b5d0a35

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

models/organization.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,40 @@ import connector from "./databaseUtil";
22

33
const organizationSchema = {
44
parent: { type: connector.Schema.Types.ObjectId, ref: "Organization", required: "true" },
5-
orgID: { type: String, required: true },
6-
orgName: { type: String, required: true },
7-
orgAddress: { type: String, required: true },
8-
orgInfra: [{ type: connector.Schema.Types.ObjectId, ref: "Infrastructure", required: "true" }],
5+
startDate: { type: Date, required: true },
6+
name: { type: String, required: true },
97
accreditation: { type: connector.Schema.Types.ObjectId, ref: "Accrediation", required: "true" },
10-
department: [{ type: connector.Schema.Types.ObjectId, ref: "Department", required: "true" }],
11-
employees: [{ type: connector.Schema.Types.ObjectId, ref: "Faculty", required: "true" }],
12-
138
};
149

15-
// eslint-disable-next-line no-unused-vars
10+
1611
const Organization = connector.model("Organization", organizationSchema);
12+
13+
async function remove(filter) {
14+
const res = await Organization.findOneAndDelete(filter);
15+
return res;
16+
}
17+
18+
async function create(parent, startDate, name, accreditation) {
19+
const org = new Organization({
20+
parent,
21+
startDate,
22+
name,
23+
accreditation,
24+
});
25+
const orgDoc = await org.save();
26+
return orgDoc;
27+
}
28+
29+
async function read(filter, limit = 1) {
30+
const orgData = await Organization.find(filter).limit(limit);
31+
return orgData;
32+
}
33+
34+
async function update(filter, updateObject) {
35+
const org = await Organization.findOneAndUpdate(filter, updateObject, { new: true });
36+
return org;
37+
}
38+
39+
export default {
40+
create, read, update, remove,
41+
};

0 commit comments

Comments
 (0)