@goweekdays/core 0.0.10 → 0.0.12

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 0.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - de8f568: Add promo code
8
+
9
+ ## 0.0.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 590635e: chore: update dependencies
14
+
3
15
  ## 0.0.10
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { ObjectId, ClientSession } from 'mongodb';
3
3
  import * as bson from 'bson';
4
4
  import { Request, Response, NextFunction } from 'express';
5
5
  import { paginate } from '@goweekdays/utils';
6
+ import Joi from 'joi';
6
7
 
7
8
  type TVerificationMetadata = {
8
9
  name?: string;
@@ -65,9 +66,7 @@ declare function useVerificationService(): {
65
66
  email: string;
66
67
  metadata: TKeyValuePair;
67
68
  }) => Promise<bson.ObjectId>;
68
- verify: (id: string) => Promise<TVerification | {
69
- message: string;
70
- }>;
69
+ verify: (id: string) => Promise<TVerification>;
71
70
  getById: (id: string) => Promise<TVerification>;
72
71
  getVerifications: ({ search, page, status, type, email, limit, }?: {
73
72
  search?: string | undefined;
@@ -144,7 +143,7 @@ type TUser = {
144
143
  birthDay?: number;
145
144
  birthYear?: number;
146
145
  gender?: string;
147
- roles?: TUserRole[];
146
+ defaultOrg?: ObjectId;
148
147
  status?: string;
149
148
  referralCode?: string;
150
149
  referredBy?: string;
@@ -211,7 +210,7 @@ declare function useUserRepo(): {
211
210
  updateUserFieldById: ({ _id, field, value }?: {
212
211
  _id: string | ObjectId;
213
212
  field: string;
214
- value: string;
213
+ value: string | ObjectId;
215
214
  }, session?: ClientSession) => Promise<string>;
216
215
  addUserRole: ({ _id, role }?: {
217
216
  _id: string | ObjectId;
@@ -243,7 +242,6 @@ declare function useUserService(): {
243
242
  lastName: string;
244
243
  suffix?: string | undefined;
245
244
  type: string;
246
- roles: TUserRole[];
247
245
  }) => Promise<bson.ObjectId>;
248
246
  resetPassword: (id: string, newPassword: string, passwordConfirmation: string) => Promise<string>;
249
247
  updateName: (_id: string, firstName?: string, lastName?: string) => Promise<string>;
@@ -311,6 +309,7 @@ type TRole = {
311
309
  permissions?: Array<string>;
312
310
  type?: string;
313
311
  status?: string;
312
+ default?: boolean;
314
313
  createdBy?: string | ObjectId;
315
314
  createdAt?: string;
316
315
  updatedAt?: string;
@@ -325,6 +324,7 @@ declare class MRole implements TRole {
325
324
  permissions?: Array<string>;
326
325
  type?: string;
327
326
  status?: string;
327
+ default?: boolean;
328
328
  createdBy?: string | ObjectId;
329
329
  createdAt?: string;
330
330
  updatedAt?: string;
@@ -822,8 +822,19 @@ type TSubscription = {
822
822
  _id?: ObjectId;
823
823
  user?: ObjectId | string;
824
824
  org?: ObjectId | string;
825
- subscriptionId: string;
825
+ customerId: string;
826
+ paymentMethodId: string;
827
+ amount: number;
828
+ description?: string;
829
+ currency: string;
830
+ promoCode?: string;
831
+ type: string;
832
+ seats?: number;
826
833
  status?: string;
834
+ billingCycle: "monthly" | "yearly";
835
+ nextBillingDate?: string;
836
+ lastPaymentStatus?: string;
837
+ failedAttempts?: number;
827
838
  createdAt?: string;
828
839
  updatedAt?: string;
829
840
  deletedAt?: string;
@@ -849,6 +860,16 @@ declare function useSubscriptionRepo(): {
849
860
  pageRange: string;
850
861
  }>;
851
862
  updateStatus: (_id: string | ObjectId, status: string) => Promise<string>;
863
+ getByOrgId: (org: string | ObjectId) => Promise<TSubscription | null>;
864
+ getByAffiliateUserId: (user: string | ObjectId) => Promise<TSubscription | null>;
865
+ getDueSubscriptions: (BATCH_SIZE?: number) => Promise<TSubscription[]>;
866
+ getFailedSubscriptions: (BATCH_SIZE?: number, maxAttempts?: number) => Promise<TSubscription[]>;
867
+ processSuccessfulPayment: (value: Pick<TSubscription, "_id" | "nextBillingDate">, session?: ClientSession) => Promise<string>;
868
+ markSubscriptionAsFailed: ({ _id, failed }?: {
869
+ _id: string | ObjectId;
870
+ failed?: boolean | undefined;
871
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
872
+ markSubscriptionAsCanceled: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
852
873
  };
853
874
 
854
875
  type TOrg = {
@@ -882,27 +903,54 @@ type TAddress = {
882
903
  declare function MAddress(value: any): TAddress;
883
904
 
884
905
  declare function useSubscriptionService(): {
885
- getByUserId: (id: string) => Promise<TSubscription>;
906
+ getByUserId: (id: string) => Promise<any>;
886
907
  getStatusByUser: (user: string) => Promise<string>;
887
- createAffiliateSubscription: ({ user, amount, payment_method_id, customer_id, }?: {
888
- user?: string | undefined;
889
- amount?: number | undefined;
890
- payment_method_id?: string | undefined;
891
- customer_id?: string | undefined;
908
+ createAffiliateSubscription: (value: {
909
+ user: string;
910
+ amount: number;
911
+ currency: string;
912
+ payment_method_id: string;
913
+ payment_method_number: string;
914
+ payment_method_expiry_month?: string | undefined;
915
+ payment_method_expiry_year?: string | undefined;
916
+ payment_method_cvv?: string | undefined;
917
+ payment_method_cardholder_name?: string | undefined;
918
+ payment_method_channel: string;
919
+ payment_method_type: string;
920
+ customer_id: string;
921
+ billingAddress: TAddress;
892
922
  }) => Promise<string>;
893
923
  createOrgSubscription: (value: {
894
924
  user: string;
895
925
  amount: number;
926
+ currency: string;
896
927
  payment_method_id: string;
928
+ payment_method_number: string;
929
+ payment_method_expiry_month?: string | undefined;
930
+ payment_method_expiry_year?: string | undefined;
931
+ payment_method_cvv?: string | undefined;
932
+ payment_method_cardholder_name?: string | undefined;
933
+ payment_method_channel: string;
934
+ payment_method_type: string;
897
935
  customer_id: string;
898
936
  organization: TOrg;
899
937
  billingAddress: TAddress;
900
- }) => Promise<string>;
938
+ seats: number;
939
+ }) => Promise<{
940
+ message: string;
941
+ data: {
942
+ org: string;
943
+ };
944
+ }>;
945
+ processSubscriptions: (batchSize?: number) => Promise<void>;
946
+ retryFailedPayments: (batchSize?: number) => Promise<void>;
901
947
  };
902
948
 
903
949
  declare function useSubscriptionController(): {
904
950
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
905
951
  getByUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
952
+ getByOrgId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
953
+ getByAffiliateUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
906
954
  getSubscriptions: (req: Request, res: Response, next: NextFunction) => Promise<void>;
907
955
  getSubscriptionStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
908
956
  createAffiliateSubscription: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -932,13 +980,14 @@ declare function useXenditService(): {
932
980
  success_return_url?: string | undefined;
933
981
  failure_return_url?: string | undefined;
934
982
  }) => Promise<any>;
935
- initSubscription: ({ customer, currency, amount, paymentMethod, description, interval, }?: {
983
+ initSubscription: ({ customer, currency, amount, paymentMethod, description, interval, seats, }?: {
936
984
  customer?: string | undefined;
937
985
  currency?: string | undefined;
938
986
  amount?: number | undefined;
939
987
  paymentMethod?: string | undefined;
940
988
  description?: string | undefined;
941
989
  interval?: string | undefined;
990
+ seats?: number | undefined;
942
991
  }) => Promise<any>;
943
992
  linkPaymentMethodCard: ({ success_return_url, failure_return_url, card_number, expiry_month, expiry_year, cvv, cardholder_name, currency, }?: {
944
993
  success_return_url?: string | undefined;
@@ -959,6 +1008,16 @@ declare function useXenditService(): {
959
1008
  }) => Promise<any>;
960
1009
  checkSubscriptionStatus: (subscriptionId: string) => Promise<string>;
961
1010
  cancelSubscription: (subscriptionId: string) => Promise<string>;
1011
+ getSubscription: (id: string) => Promise<any>;
1012
+ getSubscriptionCycles: (id: string) => Promise<any>;
1013
+ pay: (value: {
1014
+ amount: number;
1015
+ currency: string;
1016
+ payment_method_id: string;
1017
+ customer_id: string;
1018
+ description?: string;
1019
+ metadata?: Record<string, any>;
1020
+ }) => Promise<any>;
962
1021
  };
963
1022
 
964
1023
  type TPaymentMethod = {
@@ -969,7 +1028,8 @@ type TPaymentMethod = {
969
1028
  description?: string;
970
1029
  type: string;
971
1030
  number: string;
972
- expiry?: string;
1031
+ month_expiry?: string;
1032
+ year_expiry?: string;
973
1033
  cvv?: string;
974
1034
  paymentId: string;
975
1035
  customerId?: string;
@@ -983,20 +1043,21 @@ declare function usePaymentMethodRepo(): {
983
1043
  createIndex: () => Promise<void>;
984
1044
  add: (value: TPaymentMethod, session?: ClientSession) => Promise<string>;
985
1045
  getByUser: (user: string | ObjectId) => Promise<bson.Document[]>;
1046
+ getByOrg: (org: string | ObjectId) => Promise<bson.Document[]>;
986
1047
  deleteById: (_id: string | ObjectId) => Promise<string>;
987
1048
  createUniqueIndex: () => Promise<void>;
988
1049
  getByPaymentMethodId: (paymentId: string | ObjectId) => Promise<TPaymentMethod | null>;
989
1050
  };
990
1051
 
991
1052
  declare function usePaymentMethodService(): {
992
- linkEWallet: ({ user, mobile_number, type, success_return_url, failure_return_url, cancel_return_url, metadata, }?: {
1053
+ linkEWallet: ({ user, org, mobile_number, type, success_return_url, failure_return_url, cancel_return_url, }?: {
993
1054
  user?: string | undefined;
1055
+ org?: string | undefined;
994
1056
  mobile_number?: string | undefined;
995
1057
  type?: string | undefined;
996
1058
  success_return_url?: string | undefined;
997
1059
  failure_return_url?: string | undefined;
998
1060
  cancel_return_url?: string | undefined;
999
- metadata?: {} | undefined;
1000
1061
  }) => Promise<{
1001
1062
  paymentMethod: any;
1002
1063
  customer: any;
@@ -1020,6 +1081,7 @@ declare function usePaymentMethodController(): {
1020
1081
  linkEWallet: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1021
1082
  linkCard: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1022
1083
  getByUser: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1084
+ getByOrg: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1023
1085
  };
1024
1086
 
1025
1087
  declare function useAddressRepo(): {
@@ -1076,6 +1138,7 @@ declare function useOrgController(): {
1076
1138
  type TMember = {
1077
1139
  _id?: ObjectId;
1078
1140
  org: string | ObjectId;
1141
+ orgName: string;
1079
1142
  name: string;
1080
1143
  user: string | ObjectId;
1081
1144
  role: string | ObjectId;
@@ -1092,7 +1155,16 @@ declare function useMemberRepo(): {
1092
1155
  createTextIndex: () => Promise<void>;
1093
1156
  add: (value: TMember, session?: ClientSession) => Promise<string>;
1094
1157
  getById: (_id: string | ObjectId) => Promise<TMember | null>;
1095
- getByOrgId: (org: string | ObjectId) => Promise<TMember[]>;
1158
+ getByUserId: ({ user, search, limit, page }?: {
1159
+ user: string | ObjectId;
1160
+ search: string;
1161
+ limit: number;
1162
+ page: number;
1163
+ }) => Promise<{
1164
+ items: any[];
1165
+ pages: number;
1166
+ pageRange: string;
1167
+ }>;
1096
1168
  getOrgsByUserId: ({ search, page, limit, sort, user, status, }?: {
1097
1169
  user: string | ObjectId;
1098
1170
  page: number;
@@ -1106,6 +1178,100 @@ declare function useMemberRepo(): {
1106
1178
  pageRange: string;
1107
1179
  }>;
1108
1180
  updateStatusByUserId: (user: string | ObjectId, status: string) => Promise<string>;
1181
+ updateName: (value: Pick<TMember, "name" | "user">, session?: ClientSession) => Promise<string>;
1182
+ };
1183
+
1184
+ declare const schema: Joi.ObjectSchema<any>;
1185
+
1186
+ type TPromoType = "tiered" | "fixed";
1187
+ type TPromoTier = {
1188
+ min: number;
1189
+ max: number;
1190
+ price: number;
1191
+ };
1192
+ type TPromoCode = {
1193
+ _id?: ObjectId;
1194
+ code: string;
1195
+ description?: string;
1196
+ type: TPromoType;
1197
+ tiers?: TPromoTier[];
1198
+ fixed_rate?: number;
1199
+ appliesTo?: string;
1200
+ createdAt?: string;
1201
+ expiresAt?: string;
1202
+ assignedTo?: string | ObjectId;
1203
+ status?: "active" | "expired" | "disabled";
1204
+ };
1205
+ declare function MPromoCode(data: TPromoCode): TPromoCode;
1206
+
1207
+ declare function usePromoCodeRepo(): {
1208
+ createIndex: () => void;
1209
+ createUniqueIndex: () => void;
1210
+ add: (value: TPromoCode) => void;
1211
+ getByCode: (code: string) => Promise<mongodb.WithId<bson.Document> | null>;
1212
+ getPromoCodes: ({ search, page, limit, sort, status, type, }?: {
1213
+ search?: string | undefined;
1214
+ page?: number | undefined;
1215
+ limit?: number | undefined;
1216
+ sort?: {} | undefined;
1217
+ status?: string | undefined;
1218
+ type?: string | undefined;
1219
+ }) => Promise<{
1220
+ items: any[];
1221
+ pages: number;
1222
+ pageRange: string;
1223
+ }>;
1224
+ };
1225
+
1226
+ declare function usePromoCodeController(): {
1227
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1228
+ getByCode: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1229
+ getPromoCodes: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1230
+ };
1231
+
1232
+ type TOrderMetadata = {
1233
+ subscriptionId?: ObjectId | string;
1234
+ cycle?: number;
1235
+ seats?: number;
1236
+ promoCode?: string;
1237
+ };
1238
+ type TOrder = {
1239
+ _id?: ObjectId;
1240
+ payment?: string;
1241
+ user?: ObjectId | string;
1242
+ org?: ObjectId | string;
1243
+ type: string;
1244
+ amount: number;
1245
+ currency: string;
1246
+ description?: string;
1247
+ metadata?: TOrderMetadata;
1248
+ status?: string;
1249
+ createdAt?: string;
1250
+ updatedAt?: string;
1251
+ deletedAt?: string;
1252
+ };
1253
+ declare function MOrder(value: TOrder): TOrder;
1254
+
1255
+ declare function useOrderRepo(): {
1256
+ createIndex: () => void;
1257
+ add: (value: TOrder, session?: ClientSession) => void;
1258
+ getOrders: ({ search, page, limit, sort, status, type, id, }?: {
1259
+ search?: string | undefined;
1260
+ page?: number | undefined;
1261
+ limit?: number | undefined;
1262
+ sort?: {} | undefined;
1263
+ status?: string | undefined;
1264
+ type?: string | undefined;
1265
+ id?: string | undefined;
1266
+ }) => Promise<{
1267
+ items: any[];
1268
+ pages: number;
1269
+ pageRange: string;
1270
+ }>;
1271
+ };
1272
+
1273
+ declare function useOrderController(): {
1274
+ getOrders: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1109
1275
  };
1110
1276
 
1111
1277
  declare const MONGO_URI: string;
@@ -1144,4 +1310,4 @@ declare const PAYPAL_API_URL: string;
1144
1310
  declare const XENDIT_SECRET_KEY: string;
1145
1311
  declare const XENDIT_BASE_URL: string;
1146
1312
 
1147
- export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MCapBldgAct, MComment, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MPaymentMethod, MRole, MSubscription, MToken, MUser, MUserRole, MVerification, MWorkflow, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, 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, TAddress, TAttachment, TCapBldgAct, TCapBldgActAssmtCriteria, TCapBldgActBasicInfo, TCapBldgActInitRevEval, TComment, TEntity, TFile, TMember, TMiniRole, TOrg, TPaymentMethod, TRole, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, TWorkflow, TWorkflowStep, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, isDev, useAddressController, useAddressRepo, useAuthController, useAuthService, useCapBldgActController, useCapBldgActRepo, useCapBldgActService, useCommentController, useCommentRepo, useCommentService, useEntityController, useEntityRepo, useEntityService, useFileController, useFileRepo, useFileService, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useVerificationController, useVerificationRepo, useVerificationService, useWorkflowController, useWorkflowRepo, useWorkflowService, useXenditService };
1313
+ export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MCapBldgAct, MComment, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrder, MOrg, MPaymentMethod, MPromoCode, MRole, MSubscription, MToken, MUser, MUserRole, MVerification, MWorkflow, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, 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, TAddress, TAttachment, TCapBldgAct, TCapBldgActAssmtCriteria, TCapBldgActBasicInfo, TCapBldgActInitRevEval, TComment, TEntity, TFile, TMember, TMiniRole, TOrder, TOrderMetadata, TOrg, TPaymentMethod, TPromoCode, TPromoTier, TRole, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, TWorkflow, TWorkflowStep, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, isDev, schema, useAddressController, useAddressRepo, useAuthController, useAuthService, useCapBldgActController, useCapBldgActRepo, useCapBldgActService, useCommentController, useCommentRepo, useCommentService, useEntityController, useEntityRepo, useEntityService, useFileController, useFileRepo, useFileService, useMemberRepo, useOrderController, useOrderRepo, useOrgController, useOrgRepo, useOrgService, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, usePromoCodeController, usePromoCodeRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useVerificationController, useVerificationRepo, useVerificationService, useWorkflowController, useWorkflowRepo, useWorkflowService, useXenditService };