@7365admin1/core 3.32.2-staging.57 → 3.32.2-staging.59
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/index.d.ts +16 -2
- package/dist/index.js +122 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6935,6 +6935,7 @@ declare function useRedDotPaymentController(): {
|
|
|
6935
6935
|
createPayment: (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
|
|
6936
6936
|
getPaymentByReference: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
6937
6937
|
updateStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
6938
|
+
getPaidBills: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
6938
6939
|
};
|
|
6939
6940
|
|
|
6940
6941
|
interface IDirectPayment extends IBaseModel {
|
|
@@ -6996,14 +6997,27 @@ type TBillingPayments = {
|
|
|
6996
6997
|
};
|
|
6997
6998
|
|
|
6998
6999
|
declare const useRedDotPaymentRepo: () => {
|
|
6999
|
-
createIndexes: () => Promise<void>;
|
|
7000
|
-
getPaymentByReference: (referenceNumber: string, session?: ClientSession) => Promise<TBillingPayments>;
|
|
7001
7000
|
paySingleUnitBill: (refId: string, payload: Partial<TUnitBilling>) => Promise<mongodb.WithId<bson.Document> | null>;
|
|
7002
7001
|
createPayment: (type: string, payload: Partial<TBillingPayments>, session?: ClientSession) => Promise<string | undefined>;
|
|
7003
7002
|
payMultipleUnitBill: (refId: string[], payload: Partial<TUnitBilling>) => Promise<{
|
|
7004
7003
|
message: string;
|
|
7005
7004
|
remainingBalance: number;
|
|
7006
7005
|
}>;
|
|
7006
|
+
getPaidBills: ({ search, page, limit, sort, month, year, unitId, }: {
|
|
7007
|
+
search?: string | undefined;
|
|
7008
|
+
page?: number | undefined;
|
|
7009
|
+
limit?: number | undefined;
|
|
7010
|
+
sort?: Record<string, any> | undefined;
|
|
7011
|
+
month?: string | undefined;
|
|
7012
|
+
year?: string | undefined;
|
|
7013
|
+
unitId: string | ObjectId;
|
|
7014
|
+
}, session?: ClientSession) => Promise<{
|
|
7015
|
+
items: any[];
|
|
7016
|
+
pages: number;
|
|
7017
|
+
pageRange: string;
|
|
7018
|
+
}>;
|
|
7019
|
+
createIndexes: () => Promise<void>;
|
|
7020
|
+
getPaymentByReference: (referenceNumber: string, session?: ClientSession) => Promise<TBillingPayments>;
|
|
7007
7021
|
updateStatus: (referenceNumber: string, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
7008
7022
|
};
|
|
7009
7023
|
|
package/dist/index.js
CHANGED
|
@@ -65221,6 +65221,76 @@ var useRedDotPaymentRepo = () => {
|
|
|
65221
65221
|
}
|
|
65222
65222
|
}
|
|
65223
65223
|
}
|
|
65224
|
+
async function getPaidBills({
|
|
65225
|
+
search = "",
|
|
65226
|
+
page = 1,
|
|
65227
|
+
limit = 10,
|
|
65228
|
+
sort = {},
|
|
65229
|
+
month,
|
|
65230
|
+
year,
|
|
65231
|
+
unitId
|
|
65232
|
+
}, session) {
|
|
65233
|
+
let _unitId;
|
|
65234
|
+
try {
|
|
65235
|
+
_unitId = new import_mongodb135.ObjectId(unitId);
|
|
65236
|
+
} catch {
|
|
65237
|
+
throw new import_node_server_utils224.BadRequestError("Invalid unit ID format.");
|
|
65238
|
+
}
|
|
65239
|
+
page = page > 0 ? page - 1 : 0;
|
|
65240
|
+
let dateExpr = {};
|
|
65241
|
+
const datePaidRange = buildDatePaidRange(month, year);
|
|
65242
|
+
if (datePaidRange) {
|
|
65243
|
+
dateExpr.datePaid = datePaidRange;
|
|
65244
|
+
}
|
|
65245
|
+
const query = {
|
|
65246
|
+
unitId: _unitId,
|
|
65247
|
+
status: "success",
|
|
65248
|
+
...search && {
|
|
65249
|
+
$or: [
|
|
65250
|
+
{ referenceNumber: { $regex: search, $options: "i" } },
|
|
65251
|
+
{ unitOwner: { $regex: search, $options: "i" } },
|
|
65252
|
+
{ method: { $regex: search, $options: "i" } },
|
|
65253
|
+
{ transaction_id: { $regex: search, $options: "i" } },
|
|
65254
|
+
{ "unitBillingItems.name": { $regex: search, $options: "i" } },
|
|
65255
|
+
{
|
|
65256
|
+
$expr: {
|
|
65257
|
+
$regexMatch: {
|
|
65258
|
+
input: { $toString: "$totalAmount" },
|
|
65259
|
+
regex: search,
|
|
65260
|
+
options: "i"
|
|
65261
|
+
}
|
|
65262
|
+
}
|
|
65263
|
+
}
|
|
65264
|
+
]
|
|
65265
|
+
},
|
|
65266
|
+
...dateExpr
|
|
65267
|
+
};
|
|
65268
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
65269
|
+
try {
|
|
65270
|
+
const basePipeline = [
|
|
65271
|
+
{ $match: query },
|
|
65272
|
+
{ $sort: sort },
|
|
65273
|
+
{ $skip: page * limit },
|
|
65274
|
+
{ $limit: limit }
|
|
65275
|
+
];
|
|
65276
|
+
const [items, countResult] = await Promise.all([
|
|
65277
|
+
paymentCollection().aggregate(basePipeline, { session }).toArray(),
|
|
65278
|
+
paymentCollection().aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
65279
|
+
]);
|
|
65280
|
+
const totalCount = countResult[0]?.total || 0;
|
|
65281
|
+
const data = (0, import_node_server_utils224.paginate)(items, page, limit, totalCount);
|
|
65282
|
+
return data;
|
|
65283
|
+
} catch (error) {
|
|
65284
|
+
if (error instanceof import_node_server_utils224.AppError) {
|
|
65285
|
+
throw error;
|
|
65286
|
+
}
|
|
65287
|
+
import_node_server_utils224.logger.log({
|
|
65288
|
+
level: "error",
|
|
65289
|
+
message: error.message
|
|
65290
|
+
});
|
|
65291
|
+
throw new import_node_server_utils224.InternalServerError("Failed to retrieve paid bills.");
|
|
65292
|
+
}
|
|
65293
|
+
}
|
|
65224
65294
|
async function paySingleUnitBill(refId, payload) {
|
|
65225
65295
|
const session = import_node_server_utils224.useAtlas.getClient()?.startSession();
|
|
65226
65296
|
try {
|
|
@@ -65383,6 +65453,28 @@ var useRedDotPaymentRepo = () => {
|
|
|
65383
65453
|
session?.endSession();
|
|
65384
65454
|
}
|
|
65385
65455
|
}
|
|
65456
|
+
function buildDatePaidRange(month, year) {
|
|
65457
|
+
if (!year)
|
|
65458
|
+
return null;
|
|
65459
|
+
const yearNum = Number(year);
|
|
65460
|
+
if (!Number.isInteger(yearNum) || yearNum < 1970 || yearNum > 9999) {
|
|
65461
|
+
throw new import_node_server_utils224.BadRequestError("Invalid year filter.");
|
|
65462
|
+
}
|
|
65463
|
+
if (month) {
|
|
65464
|
+
const monthNum = Number(month);
|
|
65465
|
+
if (!Number.isInteger(monthNum) || monthNum < 1 || monthNum > 12) {
|
|
65466
|
+
throw new import_node_server_utils224.BadRequestError("Invalid month filter.");
|
|
65467
|
+
}
|
|
65468
|
+
return {
|
|
65469
|
+
$gte: new Date(yearNum, monthNum - 1, 1),
|
|
65470
|
+
$lt: new Date(yearNum, monthNum, 1)
|
|
65471
|
+
};
|
|
65472
|
+
}
|
|
65473
|
+
return {
|
|
65474
|
+
$gte: new Date(yearNum, 0, 1),
|
|
65475
|
+
$lt: new Date(yearNum + 1, 0, 1)
|
|
65476
|
+
};
|
|
65477
|
+
}
|
|
65386
65478
|
async function updateStatus(referenceNumber, status, session) {
|
|
65387
65479
|
const reference = typeof referenceNumber === "string" ? referenceNumber.trim() : "";
|
|
65388
65480
|
if (!reference) {
|
|
@@ -65416,11 +65508,12 @@ var useRedDotPaymentRepo = () => {
|
|
|
65416
65508
|
return formattedDate;
|
|
65417
65509
|
}
|
|
65418
65510
|
return {
|
|
65419
|
-
createIndexes,
|
|
65420
|
-
getPaymentByReference,
|
|
65421
65511
|
paySingleUnitBill,
|
|
65422
65512
|
createPayment,
|
|
65423
65513
|
payMultipleUnitBill,
|
|
65514
|
+
getPaidBills,
|
|
65515
|
+
createIndexes,
|
|
65516
|
+
getPaymentByReference,
|
|
65424
65517
|
updateStatus
|
|
65425
65518
|
};
|
|
65426
65519
|
};
|
|
@@ -65569,7 +65662,8 @@ function useRedDotPaymentController() {
|
|
|
65569
65662
|
const {
|
|
65570
65663
|
createPayment: _createPayment,
|
|
65571
65664
|
updateStatus: _updateStatus,
|
|
65572
|
-
getPaymentByReference: _getPaymentByReference
|
|
65665
|
+
getPaymentByReference: _getPaymentByReference,
|
|
65666
|
+
getPaidBills: _getPaidBills
|
|
65573
65667
|
} = useRedDotPaymentRepo();
|
|
65574
65668
|
const redirectPaymentTransaction = async (req, res) => {
|
|
65575
65669
|
try {
|
|
@@ -65684,12 +65778,36 @@ function useRedDotPaymentController() {
|
|
|
65684
65778
|
return;
|
|
65685
65779
|
}
|
|
65686
65780
|
}
|
|
65781
|
+
async function getPaidBills(req, res, next) {
|
|
65782
|
+
const schema2 = import_joi127.default.object({
|
|
65783
|
+
unitId: import_joi127.default.string().hex().length(24).required(),
|
|
65784
|
+
page: import_joi127.default.number().integer().min(1).default(1),
|
|
65785
|
+
limit: import_joi127.default.number().integer().min(1).max(100).default(10),
|
|
65786
|
+
search: import_joi127.default.string().trim().allow("").default(""),
|
|
65787
|
+
month: import_joi127.default.string().pattern(/^(0?[1-9]|1[0-2])$/).allow("").optional(),
|
|
65788
|
+
year: import_joi127.default.string().pattern(/^\d{4}$/).allow("").optional()
|
|
65789
|
+
});
|
|
65790
|
+
const { error, value } = schema2.validate({ ...req.params, ...req.query });
|
|
65791
|
+
if (error) {
|
|
65792
|
+
next(new import_node_server_utils226.BadRequestError(error.message));
|
|
65793
|
+
return;
|
|
65794
|
+
}
|
|
65795
|
+
try {
|
|
65796
|
+
const bills = await _getPaidBills(value);
|
|
65797
|
+
res.json({ data: bills });
|
|
65798
|
+
return;
|
|
65799
|
+
} catch (error2) {
|
|
65800
|
+
next(error2);
|
|
65801
|
+
return;
|
|
65802
|
+
}
|
|
65803
|
+
}
|
|
65687
65804
|
return {
|
|
65688
65805
|
redirectPaymentTransaction,
|
|
65689
65806
|
enquirePaymentTransaction,
|
|
65690
65807
|
createPayment,
|
|
65691
65808
|
getPaymentByReference,
|
|
65692
|
-
updateStatus
|
|
65809
|
+
updateStatus,
|
|
65810
|
+
getPaidBills
|
|
65693
65811
|
};
|
|
65694
65812
|
}
|
|
65695
65813
|
|