@goweekdays/core 2.7.0 → 2.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 +5 -2
- package/dist/index.js +80 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1047,7 +1047,7 @@ type TLedgerBill = {
|
|
|
1047
1047
|
description: string;
|
|
1048
1048
|
amount: number;
|
|
1049
1049
|
currency: string;
|
|
1050
|
-
status: "pending" | "
|
|
1050
|
+
status: "pending" | "paid" | "overdue";
|
|
1051
1051
|
billingFrom?: string | Date;
|
|
1052
1052
|
billingTo?: string | Date;
|
|
1053
1053
|
paidAt?: string | Date;
|
|
@@ -1057,6 +1057,7 @@ type TLedgerBill = {
|
|
|
1057
1057
|
declare const ledgerBillTypes: string[];
|
|
1058
1058
|
declare const ledgerBillStatuses: string[];
|
|
1059
1059
|
declare const schemaLedgerBill: Joi.ObjectSchema<any>;
|
|
1060
|
+
declare const schemaLedgerBillingSummary: Joi.ObjectSchema<any>;
|
|
1060
1061
|
declare function modelLedgerBill(value: TLedgerBill): TLedgerBill;
|
|
1061
1062
|
|
|
1062
1063
|
declare function useLedgerBillingRepo(): {
|
|
@@ -1071,11 +1072,13 @@ declare function useLedgerBillingRepo(): {
|
|
|
1071
1072
|
status?: string | undefined;
|
|
1072
1073
|
}) => Promise<Record<string, any>>;
|
|
1073
1074
|
getById: (_id: string | ObjectId) => Promise<TLedgerBill | null>;
|
|
1075
|
+
getSummary: (status: string, org: string | ObjectId) => Promise<bson.Document>;
|
|
1074
1076
|
};
|
|
1075
1077
|
|
|
1076
1078
|
declare function useLedgerBillingController(): {
|
|
1077
1079
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1078
1080
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1081
|
+
getSummary: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1079
1082
|
};
|
|
1080
1083
|
|
|
1081
1084
|
declare const MONGO_URI: string;
|
|
@@ -1117,4 +1120,4 @@ declare const XENDIT_BASE_URL: string;
|
|
|
1117
1120
|
declare const DOMAIN: string;
|
|
1118
1121
|
declare const APP_ORG: string;
|
|
1119
1122
|
|
|
1120
|
-
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TJobPost, TLedgerBill, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, ledgerBillStatuses, ledgerBillTypes, modelApp, modelJobPost, modelLedgerBill, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaJobPost, schemaLedgerBill, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscription, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useJobPostController, useJobPostRepo, useJobPostService, useLedgerBillingController, useLedgerBillingRepo, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
|
1123
|
+
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TJobPost, TLedgerBill, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, ledgerBillStatuses, ledgerBillTypes, modelApp, modelJobPost, modelLedgerBill, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaJobPost, schemaLedgerBill, schemaLedgerBillingSummary, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscription, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useJobPostController, useJobPostRepo, useJobPostService, useLedgerBillingController, useLedgerBillingRepo, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
package/dist/index.js
CHANGED
|
@@ -95,6 +95,7 @@ __export(src_exports, {
|
|
|
95
95
|
schemaInviteMember: () => schemaInviteMember,
|
|
96
96
|
schemaJobPost: () => schemaJobPost,
|
|
97
97
|
schemaLedgerBill: () => schemaLedgerBill,
|
|
98
|
+
schemaLedgerBillingSummary: () => schemaLedgerBillingSummary,
|
|
98
99
|
schemaMember: () => schemaMember,
|
|
99
100
|
schemaMemberRole: () => schemaMemberRole,
|
|
100
101
|
schemaMemberStatus: () => schemaMemberStatus,
|
|
@@ -6761,7 +6762,7 @@ var import_utils38 = require("@goweekdays/utils");
|
|
|
6761
6762
|
var import_joi29 = __toESM(require("joi"));
|
|
6762
6763
|
var import_mongodb20 = require("mongodb");
|
|
6763
6764
|
var ledgerBillTypes = ["setup-fee", "subscription"];
|
|
6764
|
-
var ledgerBillStatuses = ["pending", "
|
|
6765
|
+
var ledgerBillStatuses = ["pending", "paid", "overdue"];
|
|
6765
6766
|
var schemaLedgerBill = import_joi29.default.object({
|
|
6766
6767
|
org: import_joi29.default.string().hex().length(24).required(),
|
|
6767
6768
|
type: import_joi29.default.string().valid(...ledgerBillTypes).required(),
|
|
@@ -6774,6 +6775,10 @@ var schemaLedgerBill = import_joi29.default.object({
|
|
|
6774
6775
|
paidAt: import_joi29.default.date().optional().allow("", null),
|
|
6775
6776
|
dueDate: import_joi29.default.date().optional().allow("", null)
|
|
6776
6777
|
});
|
|
6778
|
+
var schemaLedgerBillingSummary = import_joi29.default.object({
|
|
6779
|
+
status: import_joi29.default.string().valid(...ledgerBillStatuses).required(),
|
|
6780
|
+
org: import_joi29.default.string().hex().length(24).required()
|
|
6781
|
+
});
|
|
6777
6782
|
function modelLedgerBill(value) {
|
|
6778
6783
|
const { error } = schemaLedgerBill.validate(value);
|
|
6779
6784
|
if (error) {
|
|
@@ -6957,12 +6962,59 @@ function useLedgerBillingRepo() {
|
|
|
6957
6962
|
throw new import_utils39.InternalServerError("Failed to get ledger billing.");
|
|
6958
6963
|
}
|
|
6959
6964
|
}
|
|
6965
|
+
async function getSummary(status, org) {
|
|
6966
|
+
const { error } = schemaLedgerBillingSummary.validate({ status, org });
|
|
6967
|
+
if (error) {
|
|
6968
|
+
throw new Error(`Invalid ledger billing ID: ${error.message}`);
|
|
6969
|
+
}
|
|
6970
|
+
try {
|
|
6971
|
+
org = new import_mongodb21.ObjectId(org);
|
|
6972
|
+
} catch (error2) {
|
|
6973
|
+
throw new import_utils39.BadRequestError("Invalid ledger billing org.");
|
|
6974
|
+
}
|
|
6975
|
+
try {
|
|
6976
|
+
const cacheKey = (0, import_utils39.makeCacheKey)(namespace_collection, {
|
|
6977
|
+
org: String(org),
|
|
6978
|
+
status,
|
|
6979
|
+
tag: "getSummaryByOrgStatus"
|
|
6980
|
+
});
|
|
6981
|
+
const cachedData = await getCache(cacheKey);
|
|
6982
|
+
if (cachedData) {
|
|
6983
|
+
return cachedData;
|
|
6984
|
+
}
|
|
6985
|
+
const data = await collection.aggregate([
|
|
6986
|
+
{ $match: { org, status } },
|
|
6987
|
+
{
|
|
6988
|
+
$group: {
|
|
6989
|
+
_id: "$status",
|
|
6990
|
+
totalAmount: { $sum: "$amount" },
|
|
6991
|
+
count: { $sum: 1 }
|
|
6992
|
+
}
|
|
6993
|
+
}
|
|
6994
|
+
]).toArray();
|
|
6995
|
+
setCache(cacheKey, data[0]).then(() => {
|
|
6996
|
+
import_utils39.logger.log({
|
|
6997
|
+
level: "info",
|
|
6998
|
+
message: `Cache set for ledger billing summary: ${cacheKey}`
|
|
6999
|
+
});
|
|
7000
|
+
}).catch((err) => {
|
|
7001
|
+
import_utils39.logger.log({
|
|
7002
|
+
level: "error",
|
|
7003
|
+
message: `Failed to set cache for ledger billing summary: ${err.message}`
|
|
7004
|
+
});
|
|
7005
|
+
});
|
|
7006
|
+
return data[0];
|
|
7007
|
+
} catch (error2) {
|
|
7008
|
+
throw new import_utils39.InternalServerError("Failed to get ledger billing summary.");
|
|
7009
|
+
}
|
|
7010
|
+
}
|
|
6960
7011
|
return {
|
|
6961
7012
|
delCachedData,
|
|
6962
7013
|
createIndexes,
|
|
6963
7014
|
add,
|
|
6964
7015
|
getAll,
|
|
6965
|
-
getById
|
|
7016
|
+
getById,
|
|
7017
|
+
getSummary
|
|
6966
7018
|
};
|
|
6967
7019
|
}
|
|
6968
7020
|
|
|
@@ -6970,7 +7022,11 @@ function useLedgerBillingRepo() {
|
|
|
6970
7022
|
var import_joi31 = __toESM(require("joi"));
|
|
6971
7023
|
var import_utils40 = require("@goweekdays/utils");
|
|
6972
7024
|
function useLedgerBillingController() {
|
|
6973
|
-
const {
|
|
7025
|
+
const {
|
|
7026
|
+
getAll: _getAll,
|
|
7027
|
+
getById: _getById,
|
|
7028
|
+
getSummary: _getSummary
|
|
7029
|
+
} = useLedgerBillingRepo();
|
|
6974
7030
|
async function getAll(req, res, next) {
|
|
6975
7031
|
const query = req.query;
|
|
6976
7032
|
const validation = import_joi31.default.object({
|
|
@@ -7026,9 +7082,27 @@ function useLedgerBillingController() {
|
|
|
7026
7082
|
next(error2);
|
|
7027
7083
|
}
|
|
7028
7084
|
}
|
|
7085
|
+
async function getSummary(req, res, next) {
|
|
7086
|
+
const params = req.params;
|
|
7087
|
+
const { error } = schemaLedgerBillingSummary.validate(params);
|
|
7088
|
+
const org = req.params.org ?? "";
|
|
7089
|
+
const status = req.params.status ?? "";
|
|
7090
|
+
if (error) {
|
|
7091
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
7092
|
+
return;
|
|
7093
|
+
}
|
|
7094
|
+
try {
|
|
7095
|
+
const summary = await _getSummary(status, org);
|
|
7096
|
+
res.json(summary);
|
|
7097
|
+
return;
|
|
7098
|
+
} catch (error2) {
|
|
7099
|
+
next(error2);
|
|
7100
|
+
}
|
|
7101
|
+
}
|
|
7029
7102
|
return {
|
|
7030
7103
|
getAll,
|
|
7031
|
-
getById
|
|
7104
|
+
getById,
|
|
7105
|
+
getSummary
|
|
7032
7106
|
};
|
|
7033
7107
|
}
|
|
7034
7108
|
|
|
@@ -7245,7 +7319,7 @@ function useOrgService() {
|
|
|
7245
7319
|
description: "Setup payment during organization creation",
|
|
7246
7320
|
currency: plan.currency,
|
|
7247
7321
|
type: "setup-fee",
|
|
7248
|
-
status: "
|
|
7322
|
+
status: "paid"
|
|
7249
7323
|
},
|
|
7250
7324
|
session
|
|
7251
7325
|
);
|
|
@@ -10946,6 +11020,7 @@ function useJobPostController() {
|
|
|
10946
11020
|
schemaInviteMember,
|
|
10947
11021
|
schemaJobPost,
|
|
10948
11022
|
schemaLedgerBill,
|
|
11023
|
+
schemaLedgerBillingSummary,
|
|
10949
11024
|
schemaMember,
|
|
10950
11025
|
schemaMemberRole,
|
|
10951
11026
|
schemaMemberStatus,
|