@7365admin1/core 3.7.1 → 3.8.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +14 -13
- package/dist/index.js +456 -197
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +456 -195
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6030,7 +6030,6 @@ __export(src_exports, {
|
|
|
6030
6030
|
building_units_namespace_collection: () => building_units_namespace_collection,
|
|
6031
6031
|
buildings_namespace_collection: () => buildings_namespace_collection,
|
|
6032
6032
|
bulletin_boards_namespace_collection: () => bulletin_boards_namespace_collection,
|
|
6033
|
-
calculatePercentage: () => calculatePercentage,
|
|
6034
6033
|
chatSchema: () => chatSchema,
|
|
6035
6034
|
createManpowerRemarksDaily: () => createManpowerRemarksDaily,
|
|
6036
6035
|
customerSchema: () => customerSchema,
|
|
@@ -6041,7 +6040,6 @@ __export(src_exports, {
|
|
|
6041
6040
|
feedbacks2_namespace_collection: () => feedbacks2_namespace_collection,
|
|
6042
6041
|
feedbacks_namespace_collection: () => feedbacks_namespace_collection,
|
|
6043
6042
|
formatDahuaDate: () => formatDahuaDate,
|
|
6044
|
-
getPeriodRangeWithPrevious: () => getPeriodRangeWithPrevious,
|
|
6045
6043
|
guests_namespace_collection: () => guests_namespace_collection,
|
|
6046
6044
|
incidentReportLog: () => incidentReportLog,
|
|
6047
6045
|
incidents_namespace_collection: () => incidents_namespace_collection,
|
|
@@ -33515,6 +33513,176 @@ var KeyRepo = class {
|
|
|
33515
33513
|
}
|
|
33516
33514
|
};
|
|
33517
33515
|
|
|
33516
|
+
// src/services/notification.service.ts
|
|
33517
|
+
var import_iservice365_expo_notifications = require("iservice365-expo-notifications");
|
|
33518
|
+
|
|
33519
|
+
// src/repositories/push-token.repository.ts
|
|
33520
|
+
var PushTokenRepo = class {
|
|
33521
|
+
static collection() {
|
|
33522
|
+
return getDB().collection("push_tokens");
|
|
33523
|
+
}
|
|
33524
|
+
static async createIndexes() {
|
|
33525
|
+
await Promise.all([
|
|
33526
|
+
this.collection().createIndex({ token: 1 }, { unique: true }),
|
|
33527
|
+
this.collection().createIndex({ userId: 1, platform: 1 }),
|
|
33528
|
+
this.collection().createIndex({ siteId: 1 })
|
|
33529
|
+
]);
|
|
33530
|
+
}
|
|
33531
|
+
static async upsert(userId, token, platform, siteId, projectId, appSlug) {
|
|
33532
|
+
const now = /* @__PURE__ */ new Date();
|
|
33533
|
+
const p = platform;
|
|
33534
|
+
const existing = await this.collection().findOne({ token });
|
|
33535
|
+
if (existing) {
|
|
33536
|
+
await this.collection().updateOne(
|
|
33537
|
+
{ token },
|
|
33538
|
+
{
|
|
33539
|
+
$set: {
|
|
33540
|
+
userId,
|
|
33541
|
+
platform: p,
|
|
33542
|
+
siteId,
|
|
33543
|
+
projectId,
|
|
33544
|
+
appSlug,
|
|
33545
|
+
updatedAt: now
|
|
33546
|
+
}
|
|
33547
|
+
}
|
|
33548
|
+
);
|
|
33549
|
+
return;
|
|
33550
|
+
}
|
|
33551
|
+
await this.collection().deleteMany({ userId, platform: p });
|
|
33552
|
+
await this.collection().insertOne({
|
|
33553
|
+
userId,
|
|
33554
|
+
siteId,
|
|
33555
|
+
token,
|
|
33556
|
+
platform: p,
|
|
33557
|
+
projectId,
|
|
33558
|
+
appSlug,
|
|
33559
|
+
createdAt: now,
|
|
33560
|
+
updatedAt: now
|
|
33561
|
+
});
|
|
33562
|
+
}
|
|
33563
|
+
static async remove(token) {
|
|
33564
|
+
await this.collection().deleteMany({ token });
|
|
33565
|
+
}
|
|
33566
|
+
static async findTokensByUserIds(userIds, appSlug) {
|
|
33567
|
+
const docs = await this.collection().find({ userId: { $in: userIds }, appSlug: { $eq: appSlug } }).toArray();
|
|
33568
|
+
return docs.map((d) => d.token);
|
|
33569
|
+
}
|
|
33570
|
+
};
|
|
33571
|
+
|
|
33572
|
+
// src/services/notification.service.ts
|
|
33573
|
+
function toStringArray(recipient) {
|
|
33574
|
+
const arr = Array.isArray(recipient) ? recipient : [recipient];
|
|
33575
|
+
return arr.map((r) => r.toString());
|
|
33576
|
+
}
|
|
33577
|
+
async function send(userIds, title, body, data, isForMAMobileApp = false, appSlug) {
|
|
33578
|
+
try {
|
|
33579
|
+
let tokens = [];
|
|
33580
|
+
if (isForMAMobileApp) {
|
|
33581
|
+
tokens = await PushTokenRepo.findTokensByUserIds(userIds, appSlug);
|
|
33582
|
+
} else {
|
|
33583
|
+
tokens = await PushTokenRepo.findTokensByUserIds(userIds);
|
|
33584
|
+
}
|
|
33585
|
+
if (!tokens.length)
|
|
33586
|
+
return;
|
|
33587
|
+
for (const token of tokens) {
|
|
33588
|
+
await (0, import_iservice365_expo_notifications.sendExpoPushNotifications)([token], { title, body, data });
|
|
33589
|
+
}
|
|
33590
|
+
} catch (error) {
|
|
33591
|
+
console.warn("[NotificationService]", error);
|
|
33592
|
+
}
|
|
33593
|
+
}
|
|
33594
|
+
var NotificationService = class {
|
|
33595
|
+
static async bulletinBoardCreated(payload) {
|
|
33596
|
+
await send(
|
|
33597
|
+
toStringArray(payload.to),
|
|
33598
|
+
"Bulletin Board",
|
|
33599
|
+
`There is new ${payload.status} bulletin board.`,
|
|
33600
|
+
{
|
|
33601
|
+
bulletinId: payload.bulletinId.toString(),
|
|
33602
|
+
status: payload.status,
|
|
33603
|
+
module: "feedback",
|
|
33604
|
+
screen: "/(user)/bulletinInfo",
|
|
33605
|
+
params: {
|
|
33606
|
+
id: payload.bulletinId.toString()
|
|
33607
|
+
}
|
|
33608
|
+
},
|
|
33609
|
+
false,
|
|
33610
|
+
"iservice365-resident-mobile-app"
|
|
33611
|
+
);
|
|
33612
|
+
}
|
|
33613
|
+
static async prelovedMarketplacePostCreation(payload) {
|
|
33614
|
+
await send(
|
|
33615
|
+
toStringArray(payload.to),
|
|
33616
|
+
"Preloved Marketplace",
|
|
33617
|
+
`New preloved marketplace post added.`,
|
|
33618
|
+
{
|
|
33619
|
+
prelovedId: payload.prelovedId.toString(),
|
|
33620
|
+
status: payload.status,
|
|
33621
|
+
module: "prelovedMarketplace",
|
|
33622
|
+
screen: "/(user)/(marketplace)/prelovedPostInfo",
|
|
33623
|
+
params: {
|
|
33624
|
+
id: payload.prelovedId.toString()
|
|
33625
|
+
}
|
|
33626
|
+
},
|
|
33627
|
+
false,
|
|
33628
|
+
"iservice365-resident-mobile-app"
|
|
33629
|
+
);
|
|
33630
|
+
}
|
|
33631
|
+
static async bulletinBoardCreatedForMA(payload) {
|
|
33632
|
+
await send(
|
|
33633
|
+
toStringArray(payload.to),
|
|
33634
|
+
"Bulletin Board",
|
|
33635
|
+
`There is new ${payload.status} bulletin board.`,
|
|
33636
|
+
{
|
|
33637
|
+
bulletinId: payload.bulletinId.toString(),
|
|
33638
|
+
status: payload.status,
|
|
33639
|
+
module: "feedback",
|
|
33640
|
+
screen: "/(user)/(bulletin-board)",
|
|
33641
|
+
params: {
|
|
33642
|
+
id: payload.bulletinId.toString()
|
|
33643
|
+
}
|
|
33644
|
+
},
|
|
33645
|
+
true,
|
|
33646
|
+
"iservice365-ma-mobile-app"
|
|
33647
|
+
);
|
|
33648
|
+
}
|
|
33649
|
+
static async eventCreatedForMA(payload) {
|
|
33650
|
+
await send(
|
|
33651
|
+
toStringArray(payload.to),
|
|
33652
|
+
"Event",
|
|
33653
|
+
`There is new ${payload.status} event.`,
|
|
33654
|
+
{
|
|
33655
|
+
eventId: payload.eventId.toString(),
|
|
33656
|
+
status: payload.status,
|
|
33657
|
+
module: "event",
|
|
33658
|
+
screen: "/(user)/(events)",
|
|
33659
|
+
params: {
|
|
33660
|
+
id: payload.eventId.toString()
|
|
33661
|
+
}
|
|
33662
|
+
},
|
|
33663
|
+
true,
|
|
33664
|
+
"iservice365-ma-mobile-app"
|
|
33665
|
+
);
|
|
33666
|
+
}
|
|
33667
|
+
static async invitedVisitorCheckOutForMa(payload) {
|
|
33668
|
+
await send(
|
|
33669
|
+
toStringArray(payload.to),
|
|
33670
|
+
"Invited Visitor Check Out",
|
|
33671
|
+
`The invited visitor ${payload.name}, has been checked out.`,
|
|
33672
|
+
{
|
|
33673
|
+
visitorTransactionId: payload._id.toString(),
|
|
33674
|
+
module: "visitors",
|
|
33675
|
+
screen: "/(user)/visitor-management",
|
|
33676
|
+
params: {
|
|
33677
|
+
id: payload._id.toString()
|
|
33678
|
+
}
|
|
33679
|
+
},
|
|
33680
|
+
true,
|
|
33681
|
+
"iservice365-ma-mobile-app"
|
|
33682
|
+
);
|
|
33683
|
+
}
|
|
33684
|
+
};
|
|
33685
|
+
|
|
33518
33686
|
// src/services/visitor-transaction.service.ts
|
|
33519
33687
|
function useVisitorTransactionService() {
|
|
33520
33688
|
const MailerConfig = {
|
|
@@ -33553,6 +33721,7 @@ function useVisitorTransactionService() {
|
|
|
33553
33721
|
getBlocklistedVehicleByPlateNumber: _getBlocklistedVehicleByPlateNumber
|
|
33554
33722
|
} = useVehicleRepo();
|
|
33555
33723
|
const { getById: _getUnitById } = useBuildingUnitRepo();
|
|
33724
|
+
const { getUsersBySiteId } = useMemberRepo();
|
|
33556
33725
|
function extractKeyId(item) {
|
|
33557
33726
|
if (!item)
|
|
33558
33727
|
return null;
|
|
@@ -33701,7 +33870,10 @@ function useVisitorTransactionService() {
|
|
|
33701
33870
|
for (let i = 0; i < value.members.length; i += chunkSize) {
|
|
33702
33871
|
const chunk = value.members.slice(i, i + chunkSize);
|
|
33703
33872
|
for (const member of chunk) {
|
|
33704
|
-
await KeyRepo.checkPassKeyAvailability(
|
|
33873
|
+
await KeyRepo.checkPassKeyAvailability(
|
|
33874
|
+
member.visitorPass,
|
|
33875
|
+
member.passKeys
|
|
33876
|
+
);
|
|
33705
33877
|
if (member.visitorPass && Array.isArray(member.visitorPass) && member.visitorPass.length > 0) {
|
|
33706
33878
|
for (const vp of member.visitorPass) {
|
|
33707
33879
|
try {
|
|
@@ -33990,6 +34162,28 @@ function useVisitorTransactionService() {
|
|
|
33990
34162
|
}
|
|
33991
34163
|
}
|
|
33992
34164
|
console.log("Open barrier response:", openBarrier);
|
|
34165
|
+
const visitorTransaction = await _getVisitorTransactionById(
|
|
34166
|
+
id.toString()
|
|
34167
|
+
);
|
|
34168
|
+
if (!visitorTransaction) {
|
|
34169
|
+
throw new Error("Visitor transaction not found.");
|
|
34170
|
+
}
|
|
34171
|
+
if (value.checkOut && visitorTransaction.type === "guest" /* GUEST */) {
|
|
34172
|
+
const users = await getUsersBySiteId({
|
|
34173
|
+
status: "active",
|
|
34174
|
+
siteId: visitorTransaction.site.toString()
|
|
34175
|
+
});
|
|
34176
|
+
if (users?.length > 0) {
|
|
34177
|
+
const userIds = Array.from(
|
|
34178
|
+
new Set(users.map((item) => item.user.toString()))
|
|
34179
|
+
);
|
|
34180
|
+
NotificationService.invitedVisitorCheckOutForMa({
|
|
34181
|
+
to: userIds,
|
|
34182
|
+
name: visitorTransaction.name,
|
|
34183
|
+
_id: id.toString()
|
|
34184
|
+
});
|
|
34185
|
+
}
|
|
34186
|
+
}
|
|
33993
34187
|
await session?.commitTransaction();
|
|
33994
34188
|
return "Successfully updated visitor transaction.";
|
|
33995
34189
|
} catch (error) {
|
|
@@ -41047,120 +41241,6 @@ function useBulletinBoardRepo() {
|
|
|
41047
41241
|
// src/services/bulletin-board.service.ts
|
|
41048
41242
|
var import_node_server_utils140 = require("@7365admin1/node-server-utils");
|
|
41049
41243
|
var import_mongodb85 = require("mongodb");
|
|
41050
|
-
|
|
41051
|
-
// src/services/notification.service.ts
|
|
41052
|
-
var import_iservice365_expo_notifications = require("iservice365-expo-notifications");
|
|
41053
|
-
|
|
41054
|
-
// src/repositories/push-token.repository.ts
|
|
41055
|
-
var PushTokenRepo = class {
|
|
41056
|
-
static collection() {
|
|
41057
|
-
return getDB().collection("push_tokens");
|
|
41058
|
-
}
|
|
41059
|
-
static async createIndexes() {
|
|
41060
|
-
await Promise.all([
|
|
41061
|
-
this.collection().createIndex({ token: 1 }, { unique: true }),
|
|
41062
|
-
this.collection().createIndex({ userId: 1, platform: 1 }),
|
|
41063
|
-
this.collection().createIndex({ siteId: 1 })
|
|
41064
|
-
]);
|
|
41065
|
-
}
|
|
41066
|
-
static async upsert(userId, token, platform, siteId, projectId, appSlug) {
|
|
41067
|
-
const now = /* @__PURE__ */ new Date();
|
|
41068
|
-
const p = platform;
|
|
41069
|
-
const existing = await this.collection().findOne({ token });
|
|
41070
|
-
if (existing) {
|
|
41071
|
-
await this.collection().updateOne(
|
|
41072
|
-
{ token },
|
|
41073
|
-
{
|
|
41074
|
-
$set: {
|
|
41075
|
-
userId,
|
|
41076
|
-
platform: p,
|
|
41077
|
-
siteId,
|
|
41078
|
-
projectId,
|
|
41079
|
-
appSlug,
|
|
41080
|
-
updatedAt: now
|
|
41081
|
-
}
|
|
41082
|
-
}
|
|
41083
|
-
);
|
|
41084
|
-
return;
|
|
41085
|
-
}
|
|
41086
|
-
await this.collection().deleteMany({ userId, platform: p });
|
|
41087
|
-
await this.collection().insertOne({
|
|
41088
|
-
userId,
|
|
41089
|
-
siteId,
|
|
41090
|
-
token,
|
|
41091
|
-
platform: p,
|
|
41092
|
-
projectId,
|
|
41093
|
-
appSlug,
|
|
41094
|
-
createdAt: now,
|
|
41095
|
-
updatedAt: now
|
|
41096
|
-
});
|
|
41097
|
-
}
|
|
41098
|
-
static async remove(token) {
|
|
41099
|
-
await this.collection().deleteMany({ token });
|
|
41100
|
-
}
|
|
41101
|
-
static async findTokensByUserIds(userIds, appSlug) {
|
|
41102
|
-
const docs = await this.collection().find({ userId: { $in: userIds }, appSlug: { $eq: appSlug } }).toArray();
|
|
41103
|
-
return docs.map((d) => d.token);
|
|
41104
|
-
}
|
|
41105
|
-
};
|
|
41106
|
-
|
|
41107
|
-
// src/services/notification.service.ts
|
|
41108
|
-
function toStringArray(recipient) {
|
|
41109
|
-
const arr = Array.isArray(recipient) ? recipient : [recipient];
|
|
41110
|
-
return arr.map((r) => r.toString());
|
|
41111
|
-
}
|
|
41112
|
-
async function send(userIds, title, body, data, appSlug) {
|
|
41113
|
-
try {
|
|
41114
|
-
const tokens = Array.from(
|
|
41115
|
-
new Set(await PushTokenRepo.findTokensByUserIds(userIds, appSlug))
|
|
41116
|
-
);
|
|
41117
|
-
if (!tokens.length)
|
|
41118
|
-
return;
|
|
41119
|
-
for (const token of tokens) {
|
|
41120
|
-
await (0, import_iservice365_expo_notifications.sendExpoPushNotifications)([token], { title, body, data });
|
|
41121
|
-
}
|
|
41122
|
-
} catch (error) {
|
|
41123
|
-
console.warn("[NotificationService]", error);
|
|
41124
|
-
}
|
|
41125
|
-
}
|
|
41126
|
-
var NotificationService = class {
|
|
41127
|
-
static async bulletinBoardCreated(payload) {
|
|
41128
|
-
await send(
|
|
41129
|
-
toStringArray(payload.to),
|
|
41130
|
-
"Bulletin Board",
|
|
41131
|
-
`There is new ${payload.status} bulletin board.`,
|
|
41132
|
-
{
|
|
41133
|
-
bulletinId: payload.bulletinId.toString(),
|
|
41134
|
-
status: payload.status,
|
|
41135
|
-
module: "feedback",
|
|
41136
|
-
screen: "/(user)/bulletinInfo",
|
|
41137
|
-
params: {
|
|
41138
|
-
id: payload.bulletinId.toString()
|
|
41139
|
-
}
|
|
41140
|
-
},
|
|
41141
|
-
"iservice365-resident-mobile-app"
|
|
41142
|
-
);
|
|
41143
|
-
}
|
|
41144
|
-
static async prelovedMarketplacePostCreation(payload) {
|
|
41145
|
-
await send(
|
|
41146
|
-
toStringArray(payload.to),
|
|
41147
|
-
"Preloved Marketplace",
|
|
41148
|
-
`New preloved marketplace post added.`,
|
|
41149
|
-
{
|
|
41150
|
-
prelovedId: payload.prelovedId.toString(),
|
|
41151
|
-
status: payload.status,
|
|
41152
|
-
module: "prelovedMarketplace",
|
|
41153
|
-
screen: "/(user)/(marketplace)/prelovedPostInfo",
|
|
41154
|
-
params: {
|
|
41155
|
-
id: payload.prelovedId.toString()
|
|
41156
|
-
}
|
|
41157
|
-
},
|
|
41158
|
-
"iservice365-resident-mobile-app"
|
|
41159
|
-
);
|
|
41160
|
-
}
|
|
41161
|
-
};
|
|
41162
|
-
|
|
41163
|
-
// src/services/bulletin-board.service.ts
|
|
41164
41244
|
function useBulletinBoardService() {
|
|
41165
41245
|
const {
|
|
41166
41246
|
add: _add,
|
|
@@ -41227,6 +41307,12 @@ function useBulletinBoardService() {
|
|
|
41227
41307
|
status: bulletinBoardStatus
|
|
41228
41308
|
});
|
|
41229
41309
|
}
|
|
41310
|
+
NotificationService.bulletinBoardCreatedForMA({
|
|
41311
|
+
to: userIds,
|
|
41312
|
+
bulletinId: bulletinBoardId,
|
|
41313
|
+
subject: "Bulletin Board",
|
|
41314
|
+
status: bulletinBoardStatus
|
|
41315
|
+
});
|
|
41230
41316
|
}
|
|
41231
41317
|
await session?.commitTransaction();
|
|
41232
41318
|
return "Successfully added bulletin board.";
|
|
@@ -43154,11 +43240,27 @@ function useEventManagementService() {
|
|
|
43154
43240
|
updateEventManagementById: _updateEventManagementById,
|
|
43155
43241
|
processCompletedEvents: _processCompletedEvents
|
|
43156
43242
|
} = useEventManagementRepo();
|
|
43243
|
+
const { getUsersBySiteId } = useMemberRepo();
|
|
43157
43244
|
async function add(value) {
|
|
43158
43245
|
const session = import_node_server_utils151.useAtlas.getClient()?.startSession();
|
|
43159
43246
|
try {
|
|
43160
43247
|
session?.startTransaction();
|
|
43161
|
-
await _add(value, session);
|
|
43248
|
+
const response = await _add(value, session);
|
|
43249
|
+
console.log("response", response);
|
|
43250
|
+
const users = await getUsersBySiteId({
|
|
43251
|
+
status: "active",
|
|
43252
|
+
siteId: value.site
|
|
43253
|
+
});
|
|
43254
|
+
if (users?.length > 0) {
|
|
43255
|
+
const userIds = Array.from(
|
|
43256
|
+
new Set(users.map((item) => item.user.toString()))
|
|
43257
|
+
);
|
|
43258
|
+
NotificationService.eventCreatedForMA({
|
|
43259
|
+
to: userIds,
|
|
43260
|
+
eventId: response,
|
|
43261
|
+
status: value.status
|
|
43262
|
+
});
|
|
43263
|
+
}
|
|
43162
43264
|
await session?.commitTransaction();
|
|
43163
43265
|
return "Successfully added event.";
|
|
43164
43266
|
} catch (error) {
|
|
@@ -56514,73 +56616,6 @@ var Period = /* @__PURE__ */ ((Period2) => {
|
|
|
56514
56616
|
Period2["THIS_MONTH"] = "thisMonth";
|
|
56515
56617
|
return Period2;
|
|
56516
56618
|
})(Period || {});
|
|
56517
|
-
function getPeriodRangeWithPrevious(period) {
|
|
56518
|
-
const now = /* @__PURE__ */ new Date();
|
|
56519
|
-
let currentStart = /* @__PURE__ */ new Date();
|
|
56520
|
-
let currentEnd = /* @__PURE__ */ new Date();
|
|
56521
|
-
let previousStart = /* @__PURE__ */ new Date();
|
|
56522
|
-
let previousEnd = /* @__PURE__ */ new Date();
|
|
56523
|
-
if (period === "today" /* TODAY */) {
|
|
56524
|
-
currentStart.setHours(0, 0, 0, 0);
|
|
56525
|
-
currentEnd.setHours(23, 59, 59, 999);
|
|
56526
|
-
previousStart = new Date(currentStart);
|
|
56527
|
-
previousStart.setDate(previousStart.getDate() - 1);
|
|
56528
|
-
previousEnd = new Date(currentEnd);
|
|
56529
|
-
previousEnd.setDate(previousEnd.getDate() - 1);
|
|
56530
|
-
} else if (period === "thisWeek" /* THIS_WEEK */) {
|
|
56531
|
-
const day = now.getDay();
|
|
56532
|
-
const diffToMonday = day === 0 ? -6 : 1 - day;
|
|
56533
|
-
currentStart = new Date(now);
|
|
56534
|
-
currentStart.setDate(now.getDate() + diffToMonday);
|
|
56535
|
-
currentStart.setHours(0, 0, 0, 0);
|
|
56536
|
-
currentEnd = new Date(currentStart);
|
|
56537
|
-
currentEnd.setDate(currentStart.getDate() + 6);
|
|
56538
|
-
currentEnd.setHours(23, 59, 59, 999);
|
|
56539
|
-
previousStart = new Date(currentStart);
|
|
56540
|
-
previousStart.setDate(previousStart.getDate() - 7);
|
|
56541
|
-
previousEnd = new Date(currentEnd);
|
|
56542
|
-
previousEnd.setDate(previousEnd.getDate() - 7);
|
|
56543
|
-
} else if (period === "thisMonth" /* THIS_MONTH */) {
|
|
56544
|
-
currentStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
56545
|
-
currentEnd = new Date(
|
|
56546
|
-
now.getFullYear(),
|
|
56547
|
-
now.getMonth() + 1,
|
|
56548
|
-
0,
|
|
56549
|
-
23,
|
|
56550
|
-
59,
|
|
56551
|
-
59,
|
|
56552
|
-
999
|
|
56553
|
-
);
|
|
56554
|
-
previousStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
56555
|
-
previousEnd = new Date(
|
|
56556
|
-
now.getFullYear(),
|
|
56557
|
-
now.getMonth(),
|
|
56558
|
-
0,
|
|
56559
|
-
23,
|
|
56560
|
-
59,
|
|
56561
|
-
59,
|
|
56562
|
-
999
|
|
56563
|
-
);
|
|
56564
|
-
} else {
|
|
56565
|
-
throw new import_node_server_utils199.BadRequestError("Invalid period.");
|
|
56566
|
-
}
|
|
56567
|
-
return {
|
|
56568
|
-
current: {
|
|
56569
|
-
start: currentStart.toISOString(),
|
|
56570
|
-
end: currentEnd.toISOString()
|
|
56571
|
-
},
|
|
56572
|
-
previous: {
|
|
56573
|
-
start: previousStart.toISOString(),
|
|
56574
|
-
end: previousEnd.toISOString()
|
|
56575
|
-
}
|
|
56576
|
-
};
|
|
56577
|
-
}
|
|
56578
|
-
function calculatePercentage(current, previous) {
|
|
56579
|
-
if (previous === 0) {
|
|
56580
|
-
return current === 0 ? 0 : 100;
|
|
56581
|
-
}
|
|
56582
|
-
return Number(((current - previous) / previous * 100).toFixed(2));
|
|
56583
|
-
}
|
|
56584
56619
|
function useNewDashboardRepo() {
|
|
56585
56620
|
const db = import_node_server_utils199.useAtlas.getDb();
|
|
56586
56621
|
if (!db) {
|
|
@@ -57089,7 +57124,8 @@ function useNewDashboardRepo() {
|
|
|
57089
57124
|
currentlyOnSiteCount,
|
|
57090
57125
|
facilityReport,
|
|
57091
57126
|
yesterdayFacilityReport,
|
|
57092
|
-
todayFacilityReport
|
|
57127
|
+
todayFacilityReport,
|
|
57128
|
+
workOrderStatusReport
|
|
57093
57129
|
] = await Promise.all([
|
|
57094
57130
|
workOrderCollection.aggregate([
|
|
57095
57131
|
{
|
|
@@ -57279,6 +57315,20 @@ function useNewDashboardRepo() {
|
|
|
57279
57315
|
}
|
|
57280
57316
|
},
|
|
57281
57317
|
{ $count: "count" }
|
|
57318
|
+
]).toArray(),
|
|
57319
|
+
workOrderCollection.aggregate([
|
|
57320
|
+
{
|
|
57321
|
+
$match: {
|
|
57322
|
+
site: { $in: [siteIdObj, siteId] },
|
|
57323
|
+
createdAt: periodRange
|
|
57324
|
+
}
|
|
57325
|
+
},
|
|
57326
|
+
{
|
|
57327
|
+
$group: {
|
|
57328
|
+
_id: "$status",
|
|
57329
|
+
count: { $sum: 1 }
|
|
57330
|
+
}
|
|
57331
|
+
}
|
|
57282
57332
|
]).toArray()
|
|
57283
57333
|
]);
|
|
57284
57334
|
const wFacet = workOrderReport[0] ?? { total: [], inProgress: [] };
|
|
@@ -57287,6 +57337,23 @@ function useNewDashboardRepo() {
|
|
|
57287
57337
|
ongoing: [],
|
|
57288
57338
|
waitingApproval: []
|
|
57289
57339
|
};
|
|
57340
|
+
const workOrderStatus = {
|
|
57341
|
+
pending: 0,
|
|
57342
|
+
inProgress: 0,
|
|
57343
|
+
completed: 0
|
|
57344
|
+
};
|
|
57345
|
+
for (const item of workOrderStatusReport || []) {
|
|
57346
|
+
const rawStatus = String(item._id || "").toLowerCase().trim();
|
|
57347
|
+
if (rawStatus === "to-do" || rawStatus === "for-review") {
|
|
57348
|
+
workOrderStatus.pending += item.count || 0;
|
|
57349
|
+
} else if (rawStatus === "in-progress") {
|
|
57350
|
+
workOrderStatus.inProgress += item.count || 0;
|
|
57351
|
+
} else if (rawStatus === "completed") {
|
|
57352
|
+
workOrderStatus.completed += item.count || 0;
|
|
57353
|
+
} else {
|
|
57354
|
+
workOrderStatus.pending += item.count || 0;
|
|
57355
|
+
}
|
|
57356
|
+
}
|
|
57290
57357
|
const data = {
|
|
57291
57358
|
openWorkOrder: {
|
|
57292
57359
|
count: wFacet.total[0]?.count ?? 0,
|
|
@@ -57321,6 +57388,7 @@ function useNewDashboardRepo() {
|
|
|
57321
57388
|
yesterdayFacilityReport[0]?.count ?? 0
|
|
57322
57389
|
)
|
|
57323
57390
|
},
|
|
57391
|
+
workOrderStatus,
|
|
57324
57392
|
upcomingEvents,
|
|
57325
57393
|
todayReminders,
|
|
57326
57394
|
todayAttentions
|
|
@@ -65901,7 +65969,8 @@ var schemaUpdateChatPreloved = import_joi141.default.object({
|
|
|
65901
65969
|
reactions: import_joi141.default.string().optional().allow("", null)
|
|
65902
65970
|
});
|
|
65903
65971
|
var schemaChatPreloved = import_joi141.default.object({
|
|
65904
|
-
channelId: import_joi141.default.string().hex().length(24).
|
|
65972
|
+
channelId: import_joi141.default.string().hex().length(24).optional().allow("", null),
|
|
65973
|
+
receiverId: import_joi141.default.string().hex().length(24).optional().allow("", null),
|
|
65905
65974
|
senderId: import_joi141.default.string().hex().length(24).required(),
|
|
65906
65975
|
postId: import_joi141.default.string().hex().length(24).optional().allow("", null),
|
|
65907
65976
|
message: schemaMessage.required(),
|
|
@@ -65948,7 +66017,7 @@ function MChatPreloved(value) {
|
|
|
65948
66017
|
}
|
|
65949
66018
|
return {
|
|
65950
66019
|
_id: new import_mongodb145.ObjectId(),
|
|
65951
|
-
channelId: value.channelId ??
|
|
66020
|
+
channelId: value.channelId ?? null,
|
|
65952
66021
|
senderId: value.senderId ?? "",
|
|
65953
66022
|
postId: value.postId ?? null,
|
|
65954
66023
|
message: {
|
|
@@ -66178,7 +66247,130 @@ function useChannelPrelovedRepo() {
|
|
|
66178
66247
|
throw error;
|
|
66179
66248
|
}
|
|
66180
66249
|
}
|
|
66181
|
-
|
|
66250
|
+
async function getChatLists(currentUserId, page = 1, limit = 10, search) {
|
|
66251
|
+
const normalizedPage = page > 0 ? page - 1 : 0;
|
|
66252
|
+
const normalizedLimit = limit || 10;
|
|
66253
|
+
const _currentUserId = new import_mongodb148.ObjectId(currentUserId);
|
|
66254
|
+
const escapedSearch = search ? search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") : null;
|
|
66255
|
+
const pipeline = [
|
|
66256
|
+
{
|
|
66257
|
+
$match: {
|
|
66258
|
+
$or: [{ receiverId: _currentUserId }, { senderId: _currentUserId }]
|
|
66259
|
+
}
|
|
66260
|
+
},
|
|
66261
|
+
{
|
|
66262
|
+
$lookup: {
|
|
66263
|
+
from: "users",
|
|
66264
|
+
localField: "senderId",
|
|
66265
|
+
foreignField: "_id",
|
|
66266
|
+
pipeline: [
|
|
66267
|
+
{
|
|
66268
|
+
$project: {
|
|
66269
|
+
name: 1,
|
|
66270
|
+
profile: 1,
|
|
66271
|
+
type: 1
|
|
66272
|
+
}
|
|
66273
|
+
}
|
|
66274
|
+
],
|
|
66275
|
+
as: "senderId"
|
|
66276
|
+
}
|
|
66277
|
+
},
|
|
66278
|
+
{ $unwind: { path: "$senderId", preserveNullAndEmptyArrays: true } },
|
|
66279
|
+
{
|
|
66280
|
+
$lookup: {
|
|
66281
|
+
from: "post-preloved",
|
|
66282
|
+
localField: "postId",
|
|
66283
|
+
foreignField: "_id",
|
|
66284
|
+
pipeline: [
|
|
66285
|
+
{
|
|
66286
|
+
$project: {
|
|
66287
|
+
title: 1,
|
|
66288
|
+
description: 1,
|
|
66289
|
+
attachments: 1,
|
|
66290
|
+
price: 1,
|
|
66291
|
+
status: 1,
|
|
66292
|
+
createdBy: 1,
|
|
66293
|
+
reserverId: 1
|
|
66294
|
+
}
|
|
66295
|
+
}
|
|
66296
|
+
],
|
|
66297
|
+
as: "postDetails"
|
|
66298
|
+
}
|
|
66299
|
+
},
|
|
66300
|
+
{ $unwind: { path: "$postDetails", preserveNullAndEmptyArrays: true } },
|
|
66301
|
+
...escapedSearch ? [
|
|
66302
|
+
{
|
|
66303
|
+
$match: {
|
|
66304
|
+
$or: [
|
|
66305
|
+
{
|
|
66306
|
+
"senderId.name": {
|
|
66307
|
+
$regex: new RegExp(escapedSearch, "i")
|
|
66308
|
+
}
|
|
66309
|
+
},
|
|
66310
|
+
{
|
|
66311
|
+
"postDetails.title": {
|
|
66312
|
+
$regex: new RegExp(escapedSearch, "i")
|
|
66313
|
+
}
|
|
66314
|
+
}
|
|
66315
|
+
]
|
|
66316
|
+
}
|
|
66317
|
+
}
|
|
66318
|
+
] : [],
|
|
66319
|
+
{
|
|
66320
|
+
$lookup: {
|
|
66321
|
+
from: "chat-preloved",
|
|
66322
|
+
localField: "_id",
|
|
66323
|
+
foreignField: "channelId",
|
|
66324
|
+
pipeline: [
|
|
66325
|
+
{ $match: { deletedAt: null } },
|
|
66326
|
+
{ $sort: { createdAt: -1 } },
|
|
66327
|
+
{ $limit: 1 }
|
|
66328
|
+
],
|
|
66329
|
+
as: "latestChat"
|
|
66330
|
+
}
|
|
66331
|
+
},
|
|
66332
|
+
{ $unwind: { path: "$latestChat", preserveNullAndEmptyArrays: true } },
|
|
66333
|
+
{ $addFields: { lastMessageDate: "$latestChat.createdAt" } },
|
|
66334
|
+
{
|
|
66335
|
+
$lookup: {
|
|
66336
|
+
from: "bid-preloved",
|
|
66337
|
+
localField: "postId",
|
|
66338
|
+
foreignField: "postId",
|
|
66339
|
+
pipeline: [
|
|
66340
|
+
{ $sort: { createdAt: -1 } },
|
|
66341
|
+
{ $limit: 1 },
|
|
66342
|
+
{ $project: { price: 1, message: 1, status: 1, type: 1 } }
|
|
66343
|
+
],
|
|
66344
|
+
as: "latestBidDetails"
|
|
66345
|
+
}
|
|
66346
|
+
},
|
|
66347
|
+
{
|
|
66348
|
+
$unwind: {
|
|
66349
|
+
path: "$latestBidDetails",
|
|
66350
|
+
preserveNullAndEmptyArrays: true
|
|
66351
|
+
}
|
|
66352
|
+
},
|
|
66353
|
+
{ $sort: { lastMessageDate: -1 } },
|
|
66354
|
+
{
|
|
66355
|
+
$facet: {
|
|
66356
|
+
totalCount: [{ $count: "count" }],
|
|
66357
|
+
items: [
|
|
66358
|
+
{ $skip: normalizedPage * normalizedLimit },
|
|
66359
|
+
{ $limit: normalizedLimit }
|
|
66360
|
+
]
|
|
66361
|
+
}
|
|
66362
|
+
}
|
|
66363
|
+
];
|
|
66364
|
+
try {
|
|
66365
|
+
const result = await collection.aggregate(pipeline).toArray();
|
|
66366
|
+
const totalCount = result[0].totalCount[0]?.count ?? 0;
|
|
66367
|
+
const items = result[0].items;
|
|
66368
|
+
return (0, import_node_server_utils246.paginate)(items, normalizedPage, normalizedLimit, totalCount);
|
|
66369
|
+
} catch (error) {
|
|
66370
|
+
throw error;
|
|
66371
|
+
}
|
|
66372
|
+
}
|
|
66373
|
+
return { add, getByParticipants, getChatLists, getChannelMessages };
|
|
66182
66374
|
}
|
|
66183
66375
|
|
|
66184
66376
|
// src/services/chat-preloved.service.ts
|
|
@@ -66296,7 +66488,12 @@ function useChatPrelovedController() {
|
|
|
66296
66488
|
var import_node_server_utils249 = require("@7365admin1/node-server-utils");
|
|
66297
66489
|
var import_joi144 = __toESM(require("joi"));
|
|
66298
66490
|
function useChannelPrelovedController() {
|
|
66299
|
-
const {
|
|
66491
|
+
const {
|
|
66492
|
+
add: _add,
|
|
66493
|
+
getByParticipants: _getByParticipants,
|
|
66494
|
+
getChatLists: _getChatLists,
|
|
66495
|
+
getChannelMessages: _getChannelMessages
|
|
66496
|
+
} = useChannelPrelovedRepo();
|
|
66300
66497
|
async function add(req, res, next) {
|
|
66301
66498
|
const { error, value } = schemaChannelPreloved.validate(req.body, {
|
|
66302
66499
|
abortEarly: false
|
|
@@ -66333,9 +66530,7 @@ function useChannelPrelovedController() {
|
|
|
66333
66530
|
next(new import_node_server_utils249.BadRequestError(paramError.message));
|
|
66334
66531
|
return;
|
|
66335
66532
|
}
|
|
66336
|
-
const { error: queryError, value: query } = querySchema.validate(
|
|
66337
|
-
req.query
|
|
66338
|
-
);
|
|
66533
|
+
const { error: queryError, value: query } = querySchema.validate(req.query);
|
|
66339
66534
|
if (queryError) {
|
|
66340
66535
|
import_node_server_utils249.logger.log({ level: "error", message: queryError.message });
|
|
66341
66536
|
next(new import_node_server_utils249.BadRequestError(queryError.message));
|
|
@@ -66355,7 +66550,57 @@ function useChannelPrelovedController() {
|
|
|
66355
66550
|
next(error);
|
|
66356
66551
|
}
|
|
66357
66552
|
}
|
|
66358
|
-
|
|
66553
|
+
async function getChannel(req, res, next) {
|
|
66554
|
+
const querySchema = import_joi144.default.object({
|
|
66555
|
+
postId: import_joi144.default.string().hex().length(24).required(),
|
|
66556
|
+
receiverId: import_joi144.default.string().hex().length(24).required(),
|
|
66557
|
+
senderId: import_joi144.default.string().hex().length(24).required()
|
|
66558
|
+
});
|
|
66559
|
+
const { error, value } = querySchema.validate(req.query);
|
|
66560
|
+
if (error) {
|
|
66561
|
+
import_node_server_utils249.logger.log({ level: "error", message: error.message });
|
|
66562
|
+
next(new import_node_server_utils249.BadRequestError(error.message));
|
|
66563
|
+
return;
|
|
66564
|
+
}
|
|
66565
|
+
try {
|
|
66566
|
+
const data = await _getByParticipants(
|
|
66567
|
+
value.senderId,
|
|
66568
|
+
value.receiverId,
|
|
66569
|
+
value.postId
|
|
66570
|
+
);
|
|
66571
|
+
res.status(200).json(data);
|
|
66572
|
+
} catch (error2) {
|
|
66573
|
+
import_node_server_utils249.logger.log({ level: "error", message: error2.message });
|
|
66574
|
+
next(error2);
|
|
66575
|
+
}
|
|
66576
|
+
}
|
|
66577
|
+
async function getChatLists(req, res, next) {
|
|
66578
|
+
const querySchema = import_joi144.default.object({
|
|
66579
|
+
currentUserId: import_joi144.default.string().hex().length(24).required(),
|
|
66580
|
+
page: import_joi144.default.number().integer().min(1).default(1),
|
|
66581
|
+
limit: import_joi144.default.number().integer().min(1).max(100).default(10),
|
|
66582
|
+
search: import_joi144.default.string().optional().allow("", null)
|
|
66583
|
+
});
|
|
66584
|
+
const { error, value } = querySchema.validate(req.query);
|
|
66585
|
+
if (error) {
|
|
66586
|
+
import_node_server_utils249.logger.log({ level: "error", message: error.message });
|
|
66587
|
+
next(new import_node_server_utils249.BadRequestError(error.message));
|
|
66588
|
+
return;
|
|
66589
|
+
}
|
|
66590
|
+
try {
|
|
66591
|
+
const data = await _getChatLists(
|
|
66592
|
+
value.currentUserId,
|
|
66593
|
+
value.page,
|
|
66594
|
+
value.limit,
|
|
66595
|
+
value.search || void 0
|
|
66596
|
+
);
|
|
66597
|
+
res.status(200).json(data);
|
|
66598
|
+
} catch (error2) {
|
|
66599
|
+
import_node_server_utils249.logger.log({ level: "error", message: error2.message });
|
|
66600
|
+
next(error2);
|
|
66601
|
+
}
|
|
66602
|
+
}
|
|
66603
|
+
return { add, getChannel, getChatLists, getChannelMessages };
|
|
66359
66604
|
}
|
|
66360
66605
|
|
|
66361
66606
|
// src/models/online-forms-v2.model.ts
|
|
@@ -66579,7 +66824,23 @@ function useFormEntryRepo() {
|
|
|
66579
66824
|
{ $match: query },
|
|
66580
66825
|
{ $sort: sort },
|
|
66581
66826
|
{ $skip: page * limit },
|
|
66582
|
-
{ $limit: limit }
|
|
66827
|
+
{ $limit: limit },
|
|
66828
|
+
{
|
|
66829
|
+
$lookup: {
|
|
66830
|
+
from: "users",
|
|
66831
|
+
localField: "userId",
|
|
66832
|
+
foreignField: "_id",
|
|
66833
|
+
as: "user",
|
|
66834
|
+
pipeline: [{ $project: { name: 1 } }]
|
|
66835
|
+
}
|
|
66836
|
+
},
|
|
66837
|
+
{ $unwind: { path: "$user", preserveNullAndEmptyArrays: true } },
|
|
66838
|
+
{
|
|
66839
|
+
$addFields: {
|
|
66840
|
+
name: { $ifNull: ["$user.name", "$name"] }
|
|
66841
|
+
}
|
|
66842
|
+
},
|
|
66843
|
+
{ $project: { user: 0 } }
|
|
66583
66844
|
]).toArray();
|
|
66584
66845
|
const length = await collection.countDocuments(query);
|
|
66585
66846
|
const data = (0, import_node_server_utils250.paginate)(items, page, limit, length);
|
|
@@ -67350,7 +67611,6 @@ function useBuildingLevelController() {
|
|
|
67350
67611
|
building_units_namespace_collection,
|
|
67351
67612
|
buildings_namespace_collection,
|
|
67352
67613
|
bulletin_boards_namespace_collection,
|
|
67353
|
-
calculatePercentage,
|
|
67354
67614
|
chatSchema,
|
|
67355
67615
|
createManpowerRemarksDaily,
|
|
67356
67616
|
customerSchema,
|
|
@@ -67361,7 +67621,6 @@ function useBuildingLevelController() {
|
|
|
67361
67621
|
feedbacks2_namespace_collection,
|
|
67362
67622
|
feedbacks_namespace_collection,
|
|
67363
67623
|
formatDahuaDate,
|
|
67364
|
-
getPeriodRangeWithPrevious,
|
|
67365
67624
|
guests_namespace_collection,
|
|
67366
67625
|
incidentReportLog,
|
|
67367
67626
|
incidents_namespace_collection,
|