Skip to content

Commit e17d001

Browse files
authored
Merge pull request #91 from tcet-opensource/50-create_CRUD_for_infra_model
50 CRUD for infra
2 parents e148259 + 20cab1d commit e17d001

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

models/infra.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
import connector from "#models/databaseUtil";
22

33
const infrastructureSchema = {
4-
infraID: { type: Number, required: true },
54
infraName: { type: String, required: true },
65
infraType: { type: String, required: true },
76
infraWing: { type: String, required: true },
87
floor: { type: Number, required: true },
98
capacity: { type: Number, required: true },
109
};
1110

12-
const infrastructureModel = new connector.model("Infrastructure", infrastructureSchema);
11+
const Infrastructure = new connector.model("Infrastructure", infrastructureSchema);
12+
13+
async function remove(filter) {
14+
const res = await Infrastructure.findOneAndDelete(filter);
15+
return res;
16+
}
17+
18+
async function create(infraName, infraType, infraWing, floor, capacity) {
19+
const infrastructure = new Infrastructure({
20+
infraName,
21+
infraType,
22+
infraWing,
23+
floor,
24+
capacity,
25+
});
26+
const infrastructureDoc = await infrastructure.save();
27+
return infrastructureDoc;
28+
}
29+
30+
async function read(filter, limit = 1) {
31+
const infrastructureData = await Infrastructure.find(filter).limit(limit);
32+
return infrastructureData;
33+
}
34+
35+
async function update(filter, updateObject) {
36+
const infrastructure = await Infrastructure.findOneAndUpdate(filter, updateObject, { new: true });
37+
return infrastructure;
38+
}
39+
40+
export default {
41+
create, read, update, remove,
42+
};

0 commit comments

Comments
 (0)