@tmlmobilidade/interfaces 20250918.1353.26 → 20250918.1816.45
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.
|
@@ -15,5 +15,5 @@ declare class RideAcceptanceClass extends MongoCollectionClass<RideAcceptance, C
|
|
|
15
15
|
protected getCollectionName(): string;
|
|
16
16
|
protected getEnvName(): string;
|
|
17
17
|
}
|
|
18
|
-
export declare const rideAcceptances: RideAcceptanceClass
|
|
18
|
+
export declare const rideAcceptances: Omit<RideAcceptanceClass, 'deleteById' | 'deleteMany' | 'deleteOne' | 'insertOne' | 'updateById' | 'updateMany' | 'updateOne'>;
|
|
19
19
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
3
|
+
import { HttpException, HttpStatus } from '@tmlmobilidade/lib';
|
|
3
4
|
import { RideAcceptanceSchema, UpdateRideAcceptanceSchema } from '@tmlmobilidade/types';
|
|
4
|
-
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
5
|
+
import { AsyncSingletonProxy, compareObjects, Dates, flattenObject } from '@tmlmobilidade/utils';
|
|
5
6
|
/* * */
|
|
6
7
|
class RideAcceptanceClass extends MongoCollectionClass {
|
|
7
8
|
static _instance;
|
|
@@ -19,12 +20,72 @@ class RideAcceptanceClass extends MongoCollectionClass {
|
|
|
19
20
|
return RideAcceptanceClass._instance;
|
|
20
21
|
}
|
|
21
22
|
async createByRideId(ride_id, data) {
|
|
23
|
+
data.comments.push({
|
|
24
|
+
created_at: Dates.now('utc').unix_timestamp,
|
|
25
|
+
created_by: data.created_by || 'system',
|
|
26
|
+
message: 'Ride acceptance created',
|
|
27
|
+
type: 'note',
|
|
28
|
+
updated_at: Dates.now('utc').unix_timestamp,
|
|
29
|
+
});
|
|
22
30
|
return super.insertOne({ ...data, ride_id });
|
|
23
31
|
}
|
|
24
32
|
async findByRideId(ride_id) {
|
|
25
33
|
return super.findOne({ ride_id });
|
|
26
34
|
}
|
|
27
35
|
async updateByRideId(ride_id, data) {
|
|
36
|
+
const prevAcceptance = await this.findByRideId(ride_id);
|
|
37
|
+
if (!prevAcceptance) {
|
|
38
|
+
throw new HttpException(HttpStatus.NOT_FOUND, 'Ride acceptance not found');
|
|
39
|
+
}
|
|
40
|
+
const diff = compareObjects(prevAcceptance, data);
|
|
41
|
+
const flattenedDiff = flattenObject(diff);
|
|
42
|
+
data.comments = data.comments || prevAcceptance.comments || [];
|
|
43
|
+
for (const key of Object.keys(flattenedDiff)) {
|
|
44
|
+
if (key === 'is_locked') {
|
|
45
|
+
data.comments.push({
|
|
46
|
+
created_at: Dates.now('utc').unix_timestamp,
|
|
47
|
+
created_by: data.updated_by || 'system',
|
|
48
|
+
curr_value: data[key],
|
|
49
|
+
field: key,
|
|
50
|
+
prev_value: prevAcceptance[key],
|
|
51
|
+
type: 'field_changed',
|
|
52
|
+
updated_at: Dates.now('utc').unix_timestamp,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (key === 'acceptance_status') {
|
|
56
|
+
data.comments.push({
|
|
57
|
+
created_at: Dates.now('utc').unix_timestamp,
|
|
58
|
+
created_by: data.updated_by || 'system',
|
|
59
|
+
curr_value: data[key],
|
|
60
|
+
field: key,
|
|
61
|
+
prev_value: prevAcceptance[key],
|
|
62
|
+
type: 'field_changed',
|
|
63
|
+
updated_at: Dates.now('utc').unix_timestamp,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (key === 'justification.pto_message' && data.justification?.pto_message) {
|
|
67
|
+
data.comments.push({
|
|
68
|
+
created_at: Dates.now('utc').unix_timestamp,
|
|
69
|
+
created_by: data.updated_by || 'system',
|
|
70
|
+
curr_value: data.justification.pto_message,
|
|
71
|
+
field: key,
|
|
72
|
+
prev_value: prevAcceptance.justification?.pto_message,
|
|
73
|
+
type: 'field_changed',
|
|
74
|
+
updated_at: Dates.now('utc').unix_timestamp,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (key === 'justification.justification_cause' && data.justification?.justification_cause) {
|
|
78
|
+
data.comments.push({
|
|
79
|
+
created_at: Dates.now('utc').unix_timestamp,
|
|
80
|
+
created_by: data.updated_by || 'system',
|
|
81
|
+
curr_value: data.justification.justification_cause,
|
|
82
|
+
field: key,
|
|
83
|
+
prev_value: prevAcceptance.justification?.justification_cause,
|
|
84
|
+
type: 'field_changed',
|
|
85
|
+
updated_at: Dates.now('utc').unix_timestamp,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
28
89
|
return super.updateOne({ ride_id }, data);
|
|
29
90
|
}
|
|
30
91
|
getCollectionIndexes() {
|
package/package.json
CHANGED