payservedb 4.5.6 → 4.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/models/approvalsWorkflows.js +49 -0
- package/src/models/customer.js +6 -0
- package/src/models/water_meters.js +43 -106
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const approvalWorkflowSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
module: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
trim: true
|
|
9
|
+
},
|
|
10
|
+
facilityId: {
|
|
11
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
12
|
+
ref: 'Facility',
|
|
13
|
+
required: true,
|
|
14
|
+
index: true
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
steps: {
|
|
18
|
+
type: [
|
|
19
|
+
{
|
|
20
|
+
stepNumber: {
|
|
21
|
+
type: Number,
|
|
22
|
+
required: true,
|
|
23
|
+
min: 1
|
|
24
|
+
},
|
|
25
|
+
name: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
trim: true
|
|
29
|
+
},
|
|
30
|
+
approvers: [
|
|
31
|
+
{
|
|
32
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
33
|
+
ref: 'User',
|
|
34
|
+
required: true
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
default: []
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
timestamps: true
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const ApprovalWorkflow = mongoose.model('ApprovalWorkflow', approvalWorkflowSchema);
|
|
48
|
+
|
|
49
|
+
module.exports = ApprovalWorkflow;
|
package/src/models/customer.js
CHANGED
|
@@ -1,110 +1,47 @@
|
|
|
1
|
-
const
|
|
1
|
+
const payservedb = require('payservedb');
|
|
2
|
+
const { getModel } = require('../../../../utils/getModel');
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
required: true,
|
|
7
|
-
enum: ['analog', 'smart']
|
|
8
|
-
},
|
|
9
|
-
meterNumber: {
|
|
10
|
-
type: String,
|
|
11
|
-
required: true,
|
|
12
|
-
unique: true,
|
|
13
|
-
trim: true,
|
|
14
|
-
index: true
|
|
15
|
-
},
|
|
16
|
-
accountNumber: {
|
|
17
|
-
type: String,
|
|
18
|
-
required: true,
|
|
19
|
-
unique: true,
|
|
20
|
-
trim: true
|
|
21
|
-
},
|
|
22
|
-
facilityId: {
|
|
23
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
24
|
-
ref: 'Facility',
|
|
25
|
-
},
|
|
26
|
-
unitId: {
|
|
27
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
28
|
-
ref: 'Unit',
|
|
29
|
-
},
|
|
30
|
-
customerId: {
|
|
31
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
32
|
-
ref: 'Customer',
|
|
33
|
-
},
|
|
34
|
-
manufacturer: {
|
|
35
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
36
|
-
ref: 'MeterManufacturer',
|
|
37
|
-
},
|
|
38
|
-
protocol: {
|
|
39
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
40
|
-
ref: 'MeterProtocol',
|
|
41
|
-
},
|
|
42
|
-
size: {
|
|
43
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
44
|
-
ref: 'MeterSize',
|
|
45
|
-
},
|
|
46
|
-
initialReading: {
|
|
47
|
-
type: Number,
|
|
48
|
-
required: true,
|
|
49
|
-
min: 0,
|
|
50
|
-
default: 0
|
|
51
|
-
},
|
|
52
|
-
previousReading: {
|
|
53
|
-
type: Number,
|
|
54
|
-
min: 0,
|
|
55
|
-
},
|
|
56
|
-
currentReading: {
|
|
57
|
-
type: Number,
|
|
58
|
-
min: 0,
|
|
59
|
-
default: 0
|
|
60
|
-
},
|
|
61
|
-
lastReadingDate: {
|
|
62
|
-
type: Date,
|
|
63
|
-
default: Date.now
|
|
64
|
-
},
|
|
65
|
-
readingHistory: [{
|
|
66
|
-
previousReading: Number,
|
|
67
|
-
currentReading: Number,
|
|
68
|
-
readingDate: {
|
|
69
|
-
type: Date,
|
|
70
|
-
default: Date.now
|
|
71
|
-
},
|
|
72
|
-
readBy: String,
|
|
73
|
-
consumption: Number
|
|
74
|
-
}],
|
|
75
|
-
status: {
|
|
76
|
-
type: String,
|
|
77
|
-
required: true,
|
|
78
|
-
enum: ['open', 'closed', 'maintenance', 'faulty'],
|
|
79
|
-
default: 'open',
|
|
80
|
-
},
|
|
81
|
-
customerType: {
|
|
82
|
-
type: String,
|
|
83
|
-
enum: ['postpaid', 'prepaid'],
|
|
84
|
-
},
|
|
85
|
-
isInstalled: {
|
|
86
|
-
type: Boolean,
|
|
87
|
-
default: false
|
|
88
|
-
},
|
|
89
|
-
valveType: { // Specific to smart meters
|
|
90
|
-
type: String,
|
|
91
|
-
enum: ['automatic', 'manual'],
|
|
92
|
-
default: 'automatic'
|
|
93
|
-
},
|
|
94
|
-
accountBalance: { // Specific to smart meters
|
|
95
|
-
type: Number,
|
|
96
|
-
default: 0
|
|
97
|
-
},
|
|
98
|
-
negativeBalance: { // Specific to smart meters
|
|
99
|
-
type: Number,
|
|
100
|
-
default: 0
|
|
101
|
-
},
|
|
102
|
-
}, {
|
|
103
|
-
timestamps: true
|
|
104
|
-
});
|
|
4
|
+
const getMeterDetailsByUnit = async (request, reply) => {
|
|
5
|
+
try {
|
|
6
|
+
const { facilityId, unitId } = request.params;
|
|
105
7
|
|
|
106
|
-
|
|
8
|
+
const analogMeterModel = await getModel('WaterMeter', payservedb.WaterMeter.schema, facilityId);
|
|
9
|
+
const unitModel = await getModel('Unit', payservedb.Unit.schema, facilityId);
|
|
107
10
|
|
|
108
|
-
|
|
11
|
+
// Find the unit first
|
|
12
|
+
const unit = await unitModel.findById(unitId);
|
|
13
|
+
if (!unit) {
|
|
14
|
+
return reply.code(404).send({
|
|
15
|
+
success: false,
|
|
16
|
+
error: 'Unit not found'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
109
19
|
|
|
110
|
-
|
|
20
|
+
// Find the meter associated with this unit
|
|
21
|
+
const meter = await analogMeterModel.findOne({ unitId: unitId });
|
|
22
|
+
if (!meter) {
|
|
23
|
+
return reply.code(404).send({
|
|
24
|
+
success: false,
|
|
25
|
+
error: 'No meter found for this unit'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Return only the simplified meter information
|
|
30
|
+
return reply.code(200).send({
|
|
31
|
+
status: meter.status,
|
|
32
|
+
meterNumber: meter.meterNumber,
|
|
33
|
+
currentReading: meter.currentReading,
|
|
34
|
+
previousReading: meter.previousReading,
|
|
35
|
+
lastReadingDate: meter.lastReadingDate,
|
|
36
|
+
lastUpdated: meter.updatedAt
|
|
37
|
+
});
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error('Error in retrieving analog meter details by unit:', err);
|
|
40
|
+
return reply.code(400).send({
|
|
41
|
+
success: false,
|
|
42
|
+
error: err.message
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = getMeterDetailsByUnit;
|