@tmscloud/tbt-knex 0.0.4 → 0.0.6
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/dist/dao/driver-tracking/driver-tracking.dao.d.ts +8 -0
- package/dist/dao/driver-tracking/driver-tracking.dao.js +25 -1
- package/dist/dao/driver-tracking/driver-tracking.dao.js.map +1 -1
- package/dist/dao/duty/duty.dao.d.ts +86 -0
- package/dist/dao/duty/duty.dao.js +416 -0
- package/dist/dao/duty/duty.dao.js.map +1 -0
- package/dist/dao/duty-item-progress/duty-item-progress.dao.d.ts +59 -0
- package/dist/dao/duty-item-progress/duty-item-progress.dao.js +229 -0
- package/dist/dao/duty-item-progress/duty-item-progress.dao.js.map +1 -0
- package/dist/dao/duty-template/duty-template.dao.d.ts +66 -0
- package/dist/dao/duty-template/duty-template.dao.js +369 -0
- package/dist/dao/duty-template/duty-template.dao.js.map +1 -0
- package/dist/dao/duty-track/duty-track.dao.d.ts +52 -0
- package/dist/dao/duty-track/duty-track.dao.js +259 -0
- package/dist/dao/duty-track/duty-track.dao.js.map +1 -0
- package/dist/dao/event/event.dao.js +9 -3
- package/dist/dao/event/event.dao.js.map +1 -1
- package/dist/dao/route/route.dao.d.ts +4 -0
- package/dist/dao/route/route.dao.js +18 -0
- package/dist/dao/route/route.dao.js.map +1 -1
- package/dist/dao/system-setting/system-setting.dao.d.ts +14 -0
- package/dist/dao/system-setting/system-setting.dao.js +99 -0
- package/dist/dao/system-setting/system-setting.dao.js.map +1 -0
- package/dist/dao/trip-track/trip-track.dao.d.ts +7 -0
- package/dist/dao/trip-track/trip-track.dao.js +63 -4
- package/dist/dao/trip-track/trip-track.dao.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/driver-tracking/driver-tracking.interfaces.d.ts +5 -2
- package/dist/interfaces/duty/duty.interfaces.d.ts +48 -0
- package/dist/interfaces/duty/duty.interfaces.js +3 -0
- package/dist/interfaces/duty/duty.interfaces.js.map +1 -0
- package/dist/interfaces/duty-item-progress/duty-item-progress.interfaces.d.ts +30 -0
- package/dist/interfaces/duty-item-progress/duty-item-progress.interfaces.js +3 -0
- package/dist/interfaces/duty-item-progress/duty-item-progress.interfaces.js.map +1 -0
- package/dist/interfaces/duty-template/duty-template.interfaces.d.ts +75 -0
- package/dist/interfaces/duty-template/duty-template.interfaces.js +3 -0
- package/dist/interfaces/duty-template/duty-template.interfaces.js.map +1 -0
- package/dist/interfaces/duty-track/duty-track.interfaces.d.ts +39 -0
- package/dist/interfaces/duty-track/duty-track.interfaces.js +3 -0
- package/dist/interfaces/duty-track/duty-track.interfaces.js.map +1 -0
- package/dist/interfaces/route/route.interfaces.d.ts +1 -0
- package/dist/interfaces/system-setting/system-setting.interfaces.d.ts +27 -0
- package/dist/interfaces/system-setting/system-setting.interfaces.js +3 -0
- package/dist/interfaces/system-setting/system-setting.interfaces.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
import { IDutyItemProgress, IDutyItemProgressUpdate } from "../../interfaces/duty-item-progress/duty-item-progress.interfaces";
|
|
3
|
+
export declare class DutyItemProgressDAO {
|
|
4
|
+
private _knex?;
|
|
5
|
+
private get knex();
|
|
6
|
+
/**
|
|
7
|
+
* Create progress records for all items in a duty
|
|
8
|
+
*/
|
|
9
|
+
createForDuty(dutyId: number, items: {
|
|
10
|
+
template_item_id: number;
|
|
11
|
+
item_order: number;
|
|
12
|
+
}[], trx?: Knex.Transaction): Promise<IDutyItemProgress[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Get all progress records for a duty
|
|
15
|
+
*/
|
|
16
|
+
getByDutyId(dutyId: number): Promise<IDutyItemProgress[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Get a single progress record by UUID
|
|
19
|
+
*/
|
|
20
|
+
getByUuid(uuid: string): Promise<IDutyItemProgress | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a single progress record by ID
|
|
23
|
+
*/
|
|
24
|
+
getById(id: number): Promise<IDutyItemProgress | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Update a single item's progress status
|
|
27
|
+
*/
|
|
28
|
+
updateItemStatus(id: number, data: IDutyItemProgressUpdate): Promise<IDutyItemProgress | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Increment the loop count for a repeating route item
|
|
31
|
+
*/
|
|
32
|
+
incrementLoopCount(id: number): Promise<IDutyItemProgress | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a single code-injected item progress record
|
|
35
|
+
*/
|
|
36
|
+
createCodeInjectedItem(data: {
|
|
37
|
+
duty_id: number;
|
|
38
|
+
route_id: number;
|
|
39
|
+
item_order: number;
|
|
40
|
+
}, trx?: Knex.Transaction): Promise<IDutyItemProgress>;
|
|
41
|
+
/**
|
|
42
|
+
* Delete a code-injected item (safety: only deletes items with template_item_id IS NULL)
|
|
43
|
+
*/
|
|
44
|
+
deleteCodeInjectedItem(id: number, trx?: Knex.Transaction): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Get all code-injected items for a duty
|
|
47
|
+
*/
|
|
48
|
+
getCodeInjectedByDutyId(dutyId: number): Promise<IDutyItemProgress[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Inject a code-route into a duty's item list.
|
|
51
|
+
* Handles removing a previous injection, reverting the current item,
|
|
52
|
+
* shifting item orders, and inserting the new item — all in a transaction.
|
|
53
|
+
*/
|
|
54
|
+
injectRouteItem(dutyId: number, routeId: number, trx?: Knex.Transaction): Promise<IDutyItemProgress>;
|
|
55
|
+
/**
|
|
56
|
+
* Delete all progress records for a duty
|
|
57
|
+
*/
|
|
58
|
+
deleteByDutyId(dutyId: number): Promise<number>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DutyItemProgressDAO = void 0;
|
|
16
|
+
const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
|
|
17
|
+
class DutyItemProgressDAO {
|
|
18
|
+
get knex() {
|
|
19
|
+
if (!this._knex) {
|
|
20
|
+
this._knex = KnexConnection_1.default.getConnection();
|
|
21
|
+
}
|
|
22
|
+
return this._knex;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create progress records for all items in a duty
|
|
26
|
+
*/
|
|
27
|
+
createForDuty(dutyId, items, trx) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
if (items.length === 0)
|
|
30
|
+
return [];
|
|
31
|
+
const qb = trx || this.knex;
|
|
32
|
+
const records = items.map((item) => ({
|
|
33
|
+
duty_id: dutyId,
|
|
34
|
+
template_item_id: item.template_item_id,
|
|
35
|
+
item_order: item.item_order,
|
|
36
|
+
status: "pending",
|
|
37
|
+
loop_count: 0,
|
|
38
|
+
}));
|
|
39
|
+
const created = yield qb("duty_item_progress")
|
|
40
|
+
.insert(records)
|
|
41
|
+
.returning("*");
|
|
42
|
+
return created;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get all progress records for a duty
|
|
47
|
+
*/
|
|
48
|
+
getByDutyId(dutyId) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return this.knex("duty_item_progress")
|
|
51
|
+
.where("duty_id", dutyId)
|
|
52
|
+
.orderBy("item_order", "asc");
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get a single progress record by UUID
|
|
57
|
+
*/
|
|
58
|
+
getByUuid(uuid) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const result = yield this.knex("duty_item_progress")
|
|
61
|
+
.where("uuid", uuid)
|
|
62
|
+
.first();
|
|
63
|
+
return result || null;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get a single progress record by ID
|
|
68
|
+
*/
|
|
69
|
+
getById(id) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const result = yield this.knex("duty_item_progress")
|
|
72
|
+
.where("id", id)
|
|
73
|
+
.first();
|
|
74
|
+
return result || null;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Update a single item's progress status
|
|
79
|
+
*/
|
|
80
|
+
updateItemStatus(id, data) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const updateData = {};
|
|
83
|
+
if (data.status !== undefined)
|
|
84
|
+
updateData.status = data.status;
|
|
85
|
+
if (data.started_at !== undefined)
|
|
86
|
+
updateData.started_at = data.started_at;
|
|
87
|
+
if (data.completed_at !== undefined)
|
|
88
|
+
updateData.completed_at = data.completed_at;
|
|
89
|
+
if (data.loop_count !== undefined)
|
|
90
|
+
updateData.loop_count = data.loop_count;
|
|
91
|
+
if (data.time_at_stop !== undefined)
|
|
92
|
+
updateData.time_at_stop = data.time_at_stop;
|
|
93
|
+
updateData.updated_at = new Date();
|
|
94
|
+
const [result] = yield this.knex("duty_item_progress")
|
|
95
|
+
.where("id", id)
|
|
96
|
+
.update(updateData)
|
|
97
|
+
.returning("*");
|
|
98
|
+
return result || null;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Increment the loop count for a repeating route item
|
|
103
|
+
*/
|
|
104
|
+
incrementLoopCount(id) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const [result] = yield this.knex("duty_item_progress")
|
|
107
|
+
.where("id", id)
|
|
108
|
+
.update({
|
|
109
|
+
loop_count: this.knex.raw("loop_count + 1"),
|
|
110
|
+
updated_at: new Date(),
|
|
111
|
+
})
|
|
112
|
+
.returning("*");
|
|
113
|
+
return result || null;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a single code-injected item progress record
|
|
118
|
+
*/
|
|
119
|
+
createCodeInjectedItem(data, trx) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const qb = trx || this.knex;
|
|
122
|
+
const [created] = yield qb("duty_item_progress")
|
|
123
|
+
.insert({
|
|
124
|
+
duty_id: data.duty_id,
|
|
125
|
+
template_item_id: null,
|
|
126
|
+
route_id: data.route_id,
|
|
127
|
+
item_order: data.item_order,
|
|
128
|
+
status: "pending",
|
|
129
|
+
loop_count: 0,
|
|
130
|
+
})
|
|
131
|
+
.returning("*");
|
|
132
|
+
return created;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Delete a code-injected item (safety: only deletes items with template_item_id IS NULL)
|
|
137
|
+
*/
|
|
138
|
+
deleteCodeInjectedItem(id, trx) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const qb = trx || this.knex;
|
|
141
|
+
const result = yield qb("duty_item_progress")
|
|
142
|
+
.where("id", id)
|
|
143
|
+
.whereNull("template_item_id")
|
|
144
|
+
.delete();
|
|
145
|
+
return result > 0;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get all code-injected items for a duty
|
|
150
|
+
*/
|
|
151
|
+
getCodeInjectedByDutyId(dutyId) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
return this.knex("duty_item_progress")
|
|
154
|
+
.where("duty_id", dutyId)
|
|
155
|
+
.whereNull("template_item_id")
|
|
156
|
+
.orderBy("item_order", "asc");
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Inject a code-route into a duty's item list.
|
|
161
|
+
* Handles removing a previous injection, reverting the current item,
|
|
162
|
+
* shifting item orders, and inserting the new item — all in a transaction.
|
|
163
|
+
*/
|
|
164
|
+
injectRouteItem(dutyId, routeId, trx) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
if (!trx) {
|
|
167
|
+
return this.knex.transaction((t) => this.injectRouteItem(dutyId, routeId, t));
|
|
168
|
+
}
|
|
169
|
+
const allItems = yield trx("duty_item_progress")
|
|
170
|
+
.where("duty_id", dutyId)
|
|
171
|
+
.orderBy("item_order", "asc");
|
|
172
|
+
const previousInjection = allItems.find((i) => i.route_id != null &&
|
|
173
|
+
i.template_item_id == null &&
|
|
174
|
+
(i.status === "pending" || i.status === "in_progress"));
|
|
175
|
+
if (previousInjection) {
|
|
176
|
+
yield trx("duty_item_progress")
|
|
177
|
+
.where("id", previousInjection.id)
|
|
178
|
+
.delete();
|
|
179
|
+
yield trx("duty_item_progress")
|
|
180
|
+
.where("duty_id", dutyId)
|
|
181
|
+
.where("item_order", ">", previousInjection.item_order)
|
|
182
|
+
.decrement("item_order", 1);
|
|
183
|
+
}
|
|
184
|
+
const freshItems = yield trx("duty_item_progress")
|
|
185
|
+
.where("duty_id", dutyId)
|
|
186
|
+
.orderBy("item_order", "asc");
|
|
187
|
+
const currentItem = freshItems.find((i) => i.status === "in_progress") ||
|
|
188
|
+
freshItems.find((i) => i.status === "pending");
|
|
189
|
+
const insertOrder = currentItem ? currentItem.item_order : 0;
|
|
190
|
+
if (currentItem && currentItem.status === "in_progress") {
|
|
191
|
+
yield trx("duty_item_progress")
|
|
192
|
+
.where("id", currentItem.id)
|
|
193
|
+
.update({
|
|
194
|
+
status: "pending",
|
|
195
|
+
started_at: null,
|
|
196
|
+
completed_at: null,
|
|
197
|
+
updated_at: new Date(),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (freshItems.length > 0) {
|
|
201
|
+
yield trx("duty_item_progress")
|
|
202
|
+
.where("duty_id", dutyId)
|
|
203
|
+
.where("item_order", ">=", insertOrder)
|
|
204
|
+
.increment("item_order", 1);
|
|
205
|
+
}
|
|
206
|
+
const [created] = yield trx("duty_item_progress")
|
|
207
|
+
.insert({
|
|
208
|
+
duty_id: dutyId,
|
|
209
|
+
route_id: routeId,
|
|
210
|
+
template_item_id: null,
|
|
211
|
+
item_order: insertOrder,
|
|
212
|
+
status: "pending",
|
|
213
|
+
loop_count: 0,
|
|
214
|
+
})
|
|
215
|
+
.returning("*");
|
|
216
|
+
return created;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Delete all progress records for a duty
|
|
221
|
+
*/
|
|
222
|
+
deleteByDutyId(dutyId) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
return this.knex("duty_item_progress").where("duty_id", dutyId).delete();
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.DutyItemProgressDAO = DutyItemProgressDAO;
|
|
229
|
+
//# sourceMappingURL=duty-item-progress.dao.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duty-item-progress.dao.js","sourceRoot":"","sources":["../../../src/dao/duty-item-progress/duty-item-progress.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,0EAA+C;AAO/C,MAAa,mBAAmB;IAG9B,IAAY,IAAI;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAA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G,cAAc,CAAC,MAAc;;YACjC,OAAO,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3E,CAAC;KAAA;CACF;AAhPD,kDAgPC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IDutyTemplate, IDutyTemplateCreate, IDutyTemplateUpdate, IDutyTemplateSegment, IDutyTemplateSegmentCreate, IDutyTemplateItem, IDutyTemplateWithDetails } from "../../interfaces/duty-template/duty-template.interfaces";
|
|
2
|
+
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
3
|
+
export declare class DutyTemplateDAO implements IBaseDAO<IDutyTemplate> {
|
|
4
|
+
private _knex?;
|
|
5
|
+
private get knex();
|
|
6
|
+
/**
|
|
7
|
+
* Parse JSON fields from database results
|
|
8
|
+
*/
|
|
9
|
+
private parseTemplateJson;
|
|
10
|
+
/**
|
|
11
|
+
* Parse JSON fields for items (route join)
|
|
12
|
+
*/
|
|
13
|
+
private parseItemJson;
|
|
14
|
+
/**
|
|
15
|
+
* Base query with event and creator joins
|
|
16
|
+
*/
|
|
17
|
+
private baseQuery;
|
|
18
|
+
/**
|
|
19
|
+
* Get all duty templates with pagination
|
|
20
|
+
*/
|
|
21
|
+
getAll(page?: number, limit?: number): Promise<IDataPaginator<IDutyTemplate>>;
|
|
22
|
+
/**
|
|
23
|
+
* Get all duty templates by event ID
|
|
24
|
+
*/
|
|
25
|
+
getAllByEventId(eventId: number, page?: number, limit?: number): Promise<IDataPaginator<IDutyTemplate>>;
|
|
26
|
+
/**
|
|
27
|
+
* Get all duty templates by event UUID
|
|
28
|
+
*/
|
|
29
|
+
getAllByEventUuid(eventUuid: string, page?: number, limit?: number): Promise<IDataPaginator<IDutyTemplate>>;
|
|
30
|
+
/**
|
|
31
|
+
* Get duty template by ID
|
|
32
|
+
*/
|
|
33
|
+
getById(id: number): Promise<IDutyTemplate | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Get duty template by UUID
|
|
36
|
+
*/
|
|
37
|
+
getByUuid(uuid: string): Promise<IDutyTemplate | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Get duty template by UUID with full details (segments + items)
|
|
40
|
+
*/
|
|
41
|
+
getByUuidWithDetails(uuid: string): Promise<IDutyTemplateWithDetails | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Get segments for a template, each with their items (single batch query for items)
|
|
44
|
+
*/
|
|
45
|
+
getSegmentsByTemplateId(templateId: number): Promise<IDutyTemplateSegment[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get items for a segment, with route join for route-type items
|
|
48
|
+
*/
|
|
49
|
+
getItemsBySegmentId(segmentId: number): Promise<IDutyTemplateItem[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a duty template with optional segments and items (transactional)
|
|
52
|
+
*/
|
|
53
|
+
create(data: IDutyTemplateCreate): Promise<IDutyTemplate>;
|
|
54
|
+
/**
|
|
55
|
+
* Update a duty template by ID (metadata only, not segments)
|
|
56
|
+
*/
|
|
57
|
+
update(id: number, data: IDutyTemplateUpdate): Promise<IDutyTemplate | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Replace all segments and items for a template (transactional)
|
|
60
|
+
*/
|
|
61
|
+
replaceSegments(templateId: number, segments: IDutyTemplateSegmentCreate[]): Promise<IDutyTemplateSegment[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Delete a duty template by ID (soft delete)
|
|
64
|
+
*/
|
|
65
|
+
delete(id: number): Promise<boolean>;
|
|
66
|
+
}
|