|
1 | 1 | import connector from "#models/databaseUtil"; |
2 | 2 |
|
3 | 3 | const infrastructureSchema = { |
4 | | - infraID: { type: Number, required: true }, |
5 | 4 | infraName: { type: String, required: true }, |
6 | 5 | infraType: { type: String, required: true }, |
7 | 6 | infraWing: { type: String, required: true }, |
8 | 7 | floor: { type: Number, required: true }, |
9 | 8 | capacity: { type: Number, required: true }, |
10 | 9 | }; |
11 | 10 |
|
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