@aurispec/core-backend 1.0.4 → 1.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.
Files changed (106) hide show
  1. package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts +7 -0
  2. package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts.map +1 -0
  3. package/dist/database/migrations/1772984882048-modified_reviews_table.js +61 -0
  4. package/dist/database/migrations/1773052871526-modified_categories_table.d.ts +7 -0
  5. package/dist/database/migrations/1773052871526-modified_categories_table.d.ts.map +1 -0
  6. package/dist/database/migrations/1773052871526-modified_categories_table.js +19 -0
  7. package/dist/models/BusinessModel.d.ts +2 -0
  8. package/dist/models/BusinessModel.d.ts.map +1 -1
  9. package/dist/models/BusinessModel.js +9 -0
  10. package/dist/models/CategoryModel.d.ts +2 -0
  11. package/dist/models/CategoryModel.d.ts.map +1 -1
  12. package/dist/models/CategoryModel.js +10 -0
  13. package/dist/models/ReviewModel.d.ts +5 -0
  14. package/dist/models/ReviewModel.d.ts.map +1 -1
  15. package/dist/models/ReviewModel.js +20 -1
  16. package/dist/models/UserModel.d.ts +2 -0
  17. package/dist/models/UserModel.d.ts.map +1 -1
  18. package/dist/models/UserModel.js +9 -0
  19. package/package.json +1 -1
  20. package/dist/app.js +0 -59
  21. package/dist/common/configs/express.js +0 -29
  22. package/dist/common/configs/websocket.js +0 -17
  23. package/dist/common/constants/chat.d.ts +0 -18
  24. package/dist/common/constants/chat.d.ts.map +0 -1
  25. package/dist/common/constants/chat.js +0 -20
  26. package/dist/common/constants/messages/admin.messages.d.ts +0 -33
  27. package/dist/common/constants/messages/admin.messages.d.ts.map +0 -1
  28. package/dist/common/constants/messages/admin.messages.js +0 -35
  29. package/dist/common/constants/messages/user.messages.d.ts +0 -33
  30. package/dist/common/constants/messages/user.messages.d.ts.map +0 -1
  31. package/dist/common/constants/messages/user.messages.js +0 -35
  32. package/dist/common/dtos/AdminDto.d.ts +0 -5
  33. package/dist/common/dtos/AdminDto.d.ts.map +0 -1
  34. package/dist/common/dtos/AdminDto.js +0 -30
  35. package/dist/common/dtos/ArticleDto.d.ts +0 -11
  36. package/dist/common/dtos/ArticleDto.d.ts.map +0 -1
  37. package/dist/common/dtos/ArticleDto.js +0 -61
  38. package/dist/common/dtos/BusinessDto.d.ts +0 -12
  39. package/dist/common/dtos/BusinessDto.d.ts.map +0 -1
  40. package/dist/common/dtos/BusinessDto.js +0 -59
  41. package/dist/common/dtos/ChatDto.d.ts +0 -17
  42. package/dist/common/dtos/ChatDto.d.ts.map +0 -1
  43. package/dist/common/dtos/ChatDto.js +0 -89
  44. package/dist/common/dtos/CommonDto.d.ts +0 -13
  45. package/dist/common/dtos/CommonDto.d.ts.map +0 -1
  46. package/dist/common/dtos/CommonDto.js +0 -59
  47. package/dist/common/dtos/CommunityDto.d.ts +0 -10
  48. package/dist/common/dtos/CommunityDto.d.ts.map +0 -1
  49. package/dist/common/dtos/CommunityDto.js +0 -72
  50. package/dist/common/dtos/EventDto.d.ts +0 -24
  51. package/dist/common/dtos/EventDto.d.ts.map +0 -1
  52. package/dist/common/dtos/EventDto.js +0 -72
  53. package/dist/common/dtos/IPaginator.d.ts +0 -15
  54. package/dist/common/dtos/IPaginator.d.ts.map +0 -1
  55. package/dist/common/dtos/IPaginator.js +0 -40
  56. package/dist/common/dtos/Plan.dto.d.ts +0 -10
  57. package/dist/common/dtos/Plan.dto.d.ts.map +0 -1
  58. package/dist/common/dtos/Plan.dto.js +0 -66
  59. package/dist/common/dtos/PostDto.d.ts +0 -13
  60. package/dist/common/dtos/PostDto.d.ts.map +0 -1
  61. package/dist/common/dtos/PostDto.js +0 -75
  62. package/dist/common/dtos/ProductDto.d.ts +0 -13
  63. package/dist/common/dtos/ProductDto.d.ts.map +0 -1
  64. package/dist/common/dtos/ProductDto.js +0 -66
  65. package/dist/common/dtos/ServiceDto.d.ts +0 -19
  66. package/dist/common/dtos/ServiceDto.d.ts.map +0 -1
  67. package/dist/common/dtos/ServiceDto.js +0 -93
  68. package/dist/common/dtos/UserDto.d.ts +0 -70
  69. package/dist/common/dtos/UserDto.d.ts.map +0 -1
  70. package/dist/common/dtos/UserDto.js +0 -313
  71. package/dist/common/types/IPagination.d.ts +0 -15
  72. package/dist/common/types/IPagination.d.ts.map +0 -1
  73. package/dist/common/types/IPagination.js +0 -2
  74. package/dist/common/utils/axios.js +0 -26
  75. package/dist/common/utils/socket.js +0 -16
  76. package/dist/database/seeds/CommunityDataSeeder.js +0 -48
  77. package/dist/database/seeds/EventDataSeeder.js +0 -54
  78. package/dist/database/seeds/FeatureSeeder.js +0 -131
  79. package/dist/database/seeds/MarketplaceDataSeeder.js +0 -95
  80. package/dist/database/seeds/PlanSeeder.js +0 -78
  81. package/dist/database/seeds/UserProfileDataSeeder.js +0 -215
  82. package/dist/database/seeds/index.js +0 -39
  83. package/dist/services/StripeService.js +0 -288
  84. package/dist/services/mobile/ArticleCommentService.js +0 -479
  85. package/dist/services/mobile/ArticleService.js +0 -507
  86. package/dist/services/mobile/AuthService.js +0 -362
  87. package/dist/services/mobile/BusinessService.js +0 -267
  88. package/dist/services/mobile/BusinessServiceService.js +0 -383
  89. package/dist/services/mobile/CardService.js +0 -249
  90. package/dist/services/mobile/ChatService.js +0 -324
  91. package/dist/services/mobile/CommunityMemberService.js +0 -193
  92. package/dist/services/mobile/CommunityService.js +0 -561
  93. package/dist/services/mobile/CompleteProfileService.js +0 -308
  94. package/dist/services/mobile/ConnectionService.js +0 -338
  95. package/dist/services/mobile/EventAttendanceService.js +0 -343
  96. package/dist/services/mobile/EventService.js +0 -540
  97. package/dist/services/mobile/NotificationService.js +0 -89
  98. package/dist/services/mobile/PasswordResetService.js +0 -168
  99. package/dist/services/mobile/PlanService.js +0 -85
  100. package/dist/services/mobile/PostCommentService.js +0 -611
  101. package/dist/services/mobile/PostService.js +0 -640
  102. package/dist/services/mobile/ProductService.js +0 -360
  103. package/dist/services/mobile/RedisService.js +0 -16
  104. package/dist/services/mobile/TransactionService.js +0 -51
  105. package/dist/services/mobile/UploadService.js +0 -110
  106. package/dist/services/mobile/UserService.js +0 -128
@@ -1,360 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
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
- const typedi_1 = require("typedi");
16
- const logger_1 = require("../../common/configs/logger");
17
- const AppError_1 = require("../../common/errors/AppError");
18
- const messages_1 = require("../../common/constants/messages");
19
- const ProductRepository_1 = require("@/repositories/ProductRepository");
20
- const UploadService_1 = __importDefault(require("./UploadService"));
21
- const UploadEnum_1 = require("@/common/enums/UploadEnum");
22
- const CategoryRepository_1 = require("@/repositories/CategoryRepository");
23
- const ProductImageRepository_1 = require("@/repositories/ProductImageRepository");
24
- const BusinessRepository_1 = require("@/repositories/BusinessRepository");
25
- const configs_1 = require("@/common/configs");
26
- const Paginator_1 = require("@/transformers/Paginator");
27
- const ProductCollection_1 = require("@/transformers/collections/ProductCollection");
28
- const ProductResource_1 = require("@/transformers/resources/ProductResource");
29
- let ProductService = class ProductService {
30
- productRepository;
31
- businessRepository;
32
- uploadService;
33
- categoryRepository;
34
- productImageRepository;
35
- constructor() {
36
- this.businessRepository = new BusinessRepository_1.BusinessRepository();
37
- this.productRepository = new ProductRepository_1.ProductRepository();
38
- this.categoryRepository = new CategoryRepository_1.CategoryRepository();
39
- this.uploadService = new UploadService_1.default();
40
- this.productImageRepository = new ProductImageRepository_1.ProductImageRepository();
41
- }
42
- async createProduct(productData, user_id) {
43
- let message;
44
- const { product_name, business_id, category, price, product_images, location, description, } = productData;
45
- if (product_images && product_images?.length > 5) {
46
- message = "Maximum of 5 product images allowed";
47
- logger_1.logger.error(message);
48
- throw new AppError_1.AppError(message, 422);
49
- }
50
- const business = await this.businessRepository.getRepo().findOne({
51
- select: ['name', 'uuid', 'id'],
52
- where: {
53
- uuid: business_id,
54
- user_id
55
- }
56
- });
57
- if (!business) {
58
- message = messages_1.dynamic_messages.NOT_FOUND("Business");
59
- logger_1.logger.info(message);
60
- throw new AppError_1.AppError(message, 404);
61
- }
62
- const productCategory = await this.categoryRepository.getRepo().findOne({
63
- select: ['name', 'uuid', 'id'],
64
- where: {
65
- uuid: category
66
- }
67
- });
68
- if (!productCategory) {
69
- message = messages_1.dynamic_messages.NOT_FOUND("Product category");
70
- logger_1.logger.info(message);
71
- throw new AppError_1.AppError(message, 404);
72
- }
73
- const createdProduct = await this.productRepository.createWithCoordinates({
74
- name: product_name,
75
- business_id: business.id,
76
- category_id: productCategory.id,
77
- location,
78
- price: price.toString(),
79
- description,
80
- user_id
81
- }, location.longitude, location.latitude);
82
- const productId = createdProduct.identifiers?.[0]?.id;
83
- logger_1.logger.info("Product created without image");
84
- if (product_images?.length) {
85
- const uploadedFiles = await Promise.all(product_images.map((post_image) => this.uploadService.uploadImage(post_image, productId, UploadEnum_1.UploadDirectories.PRODUCT_IMAGES, "PostModel")));
86
- logger_1.logger.info(`Product image added successfully for: ${productId}`);
87
- await Promise.all(uploadedFiles.map((file) => this.productImageRepository.create({
88
- product_id: productId,
89
- image_id: file.id,
90
- })));
91
- }
92
- logger_1.logger.info("Product image successfully created");
93
- return {
94
- successful: true,
95
- data: null,
96
- message: "Product created successfully"
97
- };
98
- }
99
- async getProductCreationData() {
100
- const categories = await this.categoryRepository.getRepo().find({
101
- select: ['name', 'uuid']
102
- });
103
- return {
104
- successful: true,
105
- data: {
106
- categories
107
- },
108
- message: "Product creation data fetched successfully!"
109
- };
110
- }
111
- async getOneProduct(product_id, user_id) {
112
- let message;
113
- const { data } = await this.productRepository.getOneProduct(product_id, user_id);
114
- const { raw } = data;
115
- if (!raw[0]) {
116
- message = messages_1.dynamic_messages.NOT_FOUND("Product");
117
- logger_1.logger.info(message);
118
- throw new AppError_1.AppError(message, 404);
119
- }
120
- return {
121
- successful: true,
122
- data: ProductResource_1.ProductResource.toJSON(raw[0], user_id),
123
- message: "Product fetched successfully!"
124
- };
125
- }
126
- async getProductsByCategoryId(user_id, category_id, pageNumber) {
127
- let message;
128
- const page_number = pageNumber || 1;
129
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
130
- if (!category_id) {
131
- message = "Category id is required";
132
- logger_1.logger.error(message);
133
- throw new AppError_1.AppError(message, 422);
134
- }
135
- const category = await this.categoryRepository.getRepo().findOne({
136
- select: ['name', 'uuid', 'id'],
137
- where: {
138
- uuid: category_id
139
- }
140
- });
141
- if (!category) {
142
- message = messages_1.dynamic_messages.NOT_FOUND("Category");
143
- logger_1.logger.info(message);
144
- throw new AppError_1.AppError(message, 404);
145
- }
146
- const dataFetchParams = {
147
- page_number,
148
- limit,
149
- metadata: {
150
- category_id: category.id
151
- }
152
- };
153
- const { data, total, perPage, page } = await this.productRepository.loadPaginatedProductsByCategoryId(dataFetchParams, user_id);
154
- const { raw } = data;
155
- const products = (0, Paginator_1.paginator)({
156
- total,
157
- perPage,
158
- currentPage: page,
159
- data: ProductCollection_1.ProductCollection.toJSON(raw, user_id),
160
- });
161
- return {
162
- successful: true,
163
- data: products,
164
- message: "Products fetched successfully!"
165
- };
166
- }
167
- async getProductsByBusinessId(user_id, business_id, pageNumber) {
168
- let message;
169
- const page_number = pageNumber || 1;
170
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
171
- if (!business_id) {
172
- message = "Business id is required";
173
- logger_1.logger.error(message);
174
- throw new AppError_1.AppError(message, 422);
175
- }
176
- const business = await this.businessRepository.getRepo().findOne({
177
- select: ['name', 'uuid', 'id'],
178
- where: {
179
- uuid: business_id,
180
- user_id
181
- }
182
- });
183
- if (!business) {
184
- message = messages_1.dynamic_messages.NOT_FOUND("Business");
185
- logger_1.logger.info(message);
186
- throw new AppError_1.AppError(message, 404);
187
- }
188
- const dataFetchParams = {
189
- page_number,
190
- limit,
191
- metadata: {
192
- business_id: business.id
193
- }
194
- };
195
- const products = await this.loadPaginatedProducts(dataFetchParams, user_id);
196
- if (!products) {
197
- message = messages_1.dynamic_messages.NOT_FOUND("Products");
198
- logger_1.logger.info(message);
199
- throw new AppError_1.AppError(message, 404);
200
- }
201
- return {
202
- successful: true,
203
- data: products,
204
- message: "Products fetched successfully!"
205
- };
206
- }
207
- async getProducts(user_id, pageNumber) {
208
- let message;
209
- const page_number = pageNumber || 1;
210
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
211
- const dataFetchParams = {
212
- page_number,
213
- limit,
214
- };
215
- const products = await this.loadPaginatedProducts(dataFetchParams, user_id);
216
- if (!products) {
217
- message = messages_1.dynamic_messages.NOT_FOUND("Products");
218
- logger_1.logger.info(message);
219
- throw new AppError_1.AppError(message, 404);
220
- }
221
- return {
222
- successful: true,
223
- data: products,
224
- message: "Products fetched successfully!"
225
- };
226
- }
227
- async loadPaginatedProducts(loadPagesDto, userId) {
228
- const { data, total, perPage, page } = await this.productRepository.loadPaginatedProducts(loadPagesDto, userId);
229
- const { raw } = data;
230
- return (0, Paginator_1.paginator)({
231
- total,
232
- perPage,
233
- currentPage: page,
234
- data: ProductCollection_1.ProductCollection.toJSON(raw, userId),
235
- });
236
- }
237
- async updateOneProduct(productData, product_id, user_id) {
238
- let message;
239
- const { product_name, category, price, location, description, } = productData;
240
- const product = await this.productRepository.basicFindOneByConditions({
241
- uuid: product_id,
242
- user_id
243
- });
244
- if (!product) {
245
- message = messages_1.dynamic_messages.NOT_FOUND("Product");
246
- logger_1.logger.info(message);
247
- throw new AppError_1.AppError(message, 404);
248
- }
249
- const productCategory = await this.categoryRepository.getRepo().findOne({
250
- select: ['name', 'uuid', 'id'],
251
- where: {
252
- uuid: category
253
- }
254
- });
255
- if (!productCategory) {
256
- message = messages_1.dynamic_messages.NOT_FOUND("Product category");
257
- logger_1.logger.info(message);
258
- throw new AppError_1.AppError(message, 404);
259
- }
260
- await this.productRepository.updateWithCoordinates({
261
- uuid: product.uuid,
262
- user_id,
263
- }, {
264
- name: product_name,
265
- category_id: productCategory.id,
266
- location,
267
- price: price.toString(),
268
- description,
269
- }, location.longitude, location.latitude);
270
- return {
271
- successful: true,
272
- data: null,
273
- message: "Product updated successfully!"
274
- };
275
- }
276
- async deleteOneProduct(product_id, user_id) {
277
- let message;
278
- const product = await this.productRepository.basicFindOneByConditions({
279
- uuid: product_id,
280
- user_id
281
- });
282
- if (!product) {
283
- message = messages_1.dynamic_messages.NOT_FOUND("Product");
284
- logger_1.logger.info(message);
285
- throw new AppError_1.AppError(message, 404);
286
- }
287
- const productUploads = await this.productImageRepository.basicFindManyByConditions({
288
- product_id: product.id
289
- });
290
- if (productUploads?.length) {
291
- await Promise.all(productUploads.map((product_image) => this.uploadService.deleteFile(product_image.image_id, product_image?.product_id, "image")));
292
- await this.productImageRepository.deleteByCondition({ product_id: product.id });
293
- }
294
- await this.productRepository.deleteByCondition({
295
- uuid: product.uuid,
296
- user_id,
297
- });
298
- return {
299
- successful: true,
300
- data: null,
301
- message: "Product deleted successfully!"
302
- };
303
- }
304
- async searchProducts(search_string, pageNumber) {
305
- let message;
306
- const page_number = pageNumber || 1;
307
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
308
- const dataFetchParams = {
309
- page_number,
310
- limit,
311
- metadata: {
312
- search_string
313
- }
314
- };
315
- const products = await this.loadPaginatedProducts(dataFetchParams);
316
- if (!products) {
317
- message = messages_1.dynamic_messages.NOT_FOUND("Products");
318
- logger_1.logger.info(message);
319
- throw new AppError_1.AppError(message, 404);
320
- }
321
- return {
322
- successful: true,
323
- data: products,
324
- message: "Products fetched successfully!"
325
- };
326
- }
327
- async deleteProductUpload(product_id, product_image_id, user_id) {
328
- let message;
329
- const product = await this.productRepository.basicFindOneByConditions({
330
- uuid: product_id,
331
- user_id
332
- });
333
- if (!product) {
334
- message = messages_1.dynamic_messages.NOT_FOUND("Product");
335
- logger_1.logger.info(message);
336
- throw new AppError_1.AppError(message, 404);
337
- }
338
- const productUpload = await this.productImageRepository.basicFindOneByConditions({
339
- product_id: product.id,
340
- uuid: product_image_id
341
- });
342
- if (!productUpload) {
343
- message = messages_1.dynamic_messages.NOT_FOUND("Product File");
344
- logger_1.logger.info(message);
345
- throw new AppError_1.AppError(message, 404);
346
- }
347
- this.uploadService.deleteFile(productUpload.image_id, productUpload?.product_id, "image");
348
- await this.productImageRepository.deleteByCondition({ product_id: product.id });
349
- return {
350
- successful: true,
351
- data: null,
352
- message: "Product image deleted successfully!"
353
- };
354
- }
355
- };
356
- ProductService = __decorate([
357
- (0, typedi_1.Service)(),
358
- __metadata("design:paramtypes", [])
359
- ], ProductService);
360
- exports.default = ProductService;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisSessionStorage = void 0;
4
- // import { Session } from '@shopify/shopify-api';
5
- const redis_1 = require("../../common/configs/redis");
6
- class RedisSessionStorage {
7
- redis;
8
- prefix;
9
- ttl;
10
- constructor() {
11
- this.redis = (0, redis_1.getRedisWorkerClient)();
12
- this.prefix = 'shopify_session:';
13
- this.ttl = 24 * 60 * 60; // 24 hours in seconds
14
- }
15
- }
16
- exports.RedisSessionStorage = RedisSessionStorage;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransactionService = void 0;
4
- const logger_1 = require("@/common/configs/logger");
5
- const messages_1 = require("@/common/constants/messages");
6
- const AppError_1 = require("@/common/errors/AppError");
7
- const TransactionRepository_1 = require("@/repositories/TransactionRepository");
8
- const UserRepository_1 = require("@/repositories/UserRepository");
9
- const TransactionCollection_1 = require("@/transformers/collections/TransactionCollection");
10
- const TransactionResource_1 = require("@/transformers/resources/TransactionResource");
11
- class TransactionService {
12
- transactionRepository;
13
- userRepository;
14
- constructor() {
15
- this.transactionRepository = new TransactionRepository_1.TransactionRepository();
16
- this.userRepository = new UserRepository_1.UserRepository();
17
- }
18
- async fetchTransactions(user_id) {
19
- const transactions = await this.transactionRepository.findManyAndRelations({
20
- where: { user_id },
21
- relations: ['card', 'user']
22
- });
23
- return {
24
- successful: true,
25
- data: TransactionCollection_1.TransactionCollection.toJSON(transactions),
26
- message: messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("Transactions"),
27
- };
28
- }
29
- async fetchOneTransaction(user_id, transaction_id) {
30
- let message;
31
- const transaction = await this.transactionRepository.getRepo()
32
- .createQueryBuilder("transaction")
33
- .leftJoinAndSelect("transaction.user", "user")
34
- .leftJoinAndSelect("user.plan", "plan")
35
- .leftJoinAndSelect("transaction.card", "card")
36
- .where("transaction.id = :id", { uuid: transaction_id })
37
- .andWhere("transaction.user_id = :user_id", { user_id })
38
- .getOne();
39
- if (!transaction) {
40
- message = messages_1.dynamic_messages.NOT_FOUND("Trsansaction");
41
- logger_1.logger.error(message);
42
- throw new AppError_1.AppError(message, 404);
43
- }
44
- return {
45
- successful: true,
46
- data: transaction ? TransactionResource_1.TransactionResource.toJSON(transaction) : null,
47
- message: messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("Transactions"),
48
- };
49
- }
50
- }
51
- exports.TransactionService = TransactionService;
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
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
- const configs_1 = require("@/common/configs");
16
- const cloudinary_1 = __importDefault(require("@/common/configs/cloudinary"));
17
- const UploadEnum_1 = require("@/common/enums/UploadEnum");
18
- const AppError_1 = require("@/common/errors/AppError");
19
- const UploadRepository_1 = require("@/repositories/UploadRepository");
20
- const typedi_1 = require("typedi");
21
- const heic_convert_1 = __importDefault(require("heic-convert"));
22
- let UploadService = class UploadService {
23
- uploadRepository;
24
- constructor() {
25
- this.uploadRepository = new UploadRepository_1.UploadRepository();
26
- }
27
- async deleteFromCloudinary(publicId, resource_type) {
28
- return cloudinary_1.default.uploader.destroy(publicId, { resource_type });
29
- }
30
- ;
31
- async uploadToCloudinary(file, folder, resource_type) {
32
- return new Promise((resolve, reject) => {
33
- const stream = cloudinary_1.default.uploader.upload_stream({
34
- folder,
35
- resource_type,
36
- }, (error, result) => {
37
- if (error) {
38
- return reject(new AppError_1.AppError(error.message || `${file.originalname} upload failed`));
39
- }
40
- resolve(result);
41
- });
42
- stream.end(file.buffer);
43
- });
44
- }
45
- ;
46
- async normalizeImageForUpload(file) {
47
- if (file.mimetype === "image/heic" ||
48
- file.mimetype === "image/heif") {
49
- const outputBuffer = await (0, heic_convert_1.default)({
50
- buffer: file.buffer,
51
- format: "JPEG",
52
- quality: 0.9,
53
- });
54
- return {
55
- ...file,
56
- buffer: Buffer.from(outputBuffer),
57
- mimetype: "image/jpeg",
58
- originalname: file.originalname.replace(/\.(heic|heif)$/i, ".jpg"),
59
- size: Buffer.byteLength(outputBuffer),
60
- };
61
- }
62
- return file;
63
- }
64
- async uploadImage(file, uploadable_id, directory, uploadable_type) {
65
- const { MAX_FILE_SIZE, ALLOWED_FILE_TYPES } = configs_1.CONFIGS.UPLOAD.IMAGE;
66
- if (!ALLOWED_FILE_TYPES.includes(file.mimetype)) {
67
- throw new AppError_1.AppError(`Invalid file type. Allowed: ${ALLOWED_FILE_TYPES.join(", ")}`);
68
- }
69
- if (file.size > MAX_FILE_SIZE) {
70
- throw new AppError_1.AppError(`File size exceeds limit of ${MAX_FILE_SIZE / (1024 * 1024)}MB`);
71
- }
72
- const resource_type = "image";
73
- const normalizedFile = await this.normalizeImageForUpload(file);
74
- const response = await this.uploadFile(normalizedFile, directory, resource_type);
75
- return await this.uploadRepository.create({
76
- metadata: response,
77
- file_name: file.originalname,
78
- file_mimetype: file.mimetype,
79
- file_host_provider: UploadEnum_1.FILE_HOST_PROVIDER.CLOUDINARY,
80
- url: response.secure_url,
81
- uploadable_id,
82
- uploadable_type,
83
- file_size: file.size,
84
- });
85
- }
86
- async uploadFile(file, folder, resource_type) {
87
- return await this.uploadToCloudinary(file, folder, resource_type);
88
- }
89
- async deleteFile(file_id, uploadable_id, resource_type) {
90
- const uploadedFile = await this.uploadRepository.basicFindOneByConditions({
91
- id: file_id,
92
- uploadable_id
93
- });
94
- if (uploadedFile) {
95
- await this.uploadRepository.deleteByCondition({
96
- uuid: uploadedFile.uuid,
97
- uploadable_id
98
- });
99
- if (uploadedFile.file_host_provider == UploadEnum_1.FILE_HOST_PROVIDER.CLOUDINARY) {
100
- const metadata = uploadedFile?.metadata;
101
- await this.deleteFromCloudinary(metadata?.public_id, resource_type);
102
- }
103
- }
104
- }
105
- };
106
- UploadService = __decorate([
107
- (0, typedi_1.Service)(),
108
- __metadata("design:paramtypes", [])
109
- ], UploadService);
110
- exports.default = UploadService;
@@ -1,128 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
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
- const typedi_1 = require("typedi");
16
- const logger_1 = require("../../common/configs/logger");
17
- const AppError_1 = require("../../common/errors/AppError");
18
- const UserRepository_1 = require("../../repositories/UserRepository");
19
- const messages_1 = require("../../common/constants/messages");
20
- const UserResource_1 = require("@/transformers/resources/UserResource");
21
- const UploadEnum_1 = require("@/common/enums/UploadEnum");
22
- const UploadService_1 = __importDefault(require("./UploadService"));
23
- const utils_1 = require("@/common/utils");
24
- let UserService = class UserService {
25
- userRepository;
26
- userProfileRepository;
27
- uploadService;
28
- constructor() {
29
- this.userRepository = new UserRepository_1.UserRepository();
30
- this.userProfileRepository = new UserRepository_1.UserProfileRepository();
31
- this.uploadService = new UploadService_1.default();
32
- }
33
- async getProfile(user_id) {
34
- let message;
35
- const existingUser = await this.userRepository.findOneAndRelations({
36
- where: {
37
- id: user_id
38
- },
39
- relations: ["user_profile", "user_profile.avatar"]
40
- });
41
- if (!existingUser) {
42
- message = messages_1.dynamic_messages.NOT_FOUND("User");
43
- logger_1.logger.info(message);
44
- throw new AppError_1.AppError(message);
45
- }
46
- message = messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("User");
47
- return {
48
- successful: true, data: UserResource_1.UserResource.userToJSON(existingUser),
49
- message
50
- };
51
- }
52
- async getProfileByUuid(user_uuid, user_id) {
53
- let message;
54
- const existingUser = await this.userRepository.findOneAndRelations({
55
- where: {
56
- uuid: user_uuid
57
- },
58
- relations: ["user_profile", "user_profile.avatar"]
59
- });
60
- if (!existingUser) {
61
- message = messages_1.dynamic_messages.NOT_FOUND("User");
62
- logger_1.logger.info(message);
63
- throw new AppError_1.AppError(message);
64
- }
65
- message = messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("User");
66
- return {
67
- successful: true, data: UserResource_1.UserResource.userToJSON(existingUser),
68
- message
69
- };
70
- }
71
- async updateProfile(req, user_id) {
72
- const { full_name, phone, ...rest } = req;
73
- const existingProfile = await this.userProfileRepository.basicFindOneByConditions({
74
- id: user_id
75
- });
76
- await this.userRepository.updateOne({ id: user_id }, { full_name, phone });
77
- if (!existingProfile) {
78
- await this.userProfileRepository.create({ ...rest, user_id });
79
- }
80
- else {
81
- await this.userProfileRepository.updateOne({ user_id }, rest);
82
- }
83
- logger_1.logger.debug(messages_1.dynamic_messages.SUCCESSFULLY_UPDATED("Profile"));
84
- return {
85
- successful: true,
86
- data: null,
87
- message: messages_1.dynamic_messages.SUCCESSFULLY_UPDATED("Profile"),
88
- };
89
- }
90
- async updateProfileAvatar(avatar, user_id) {
91
- const existingProfile = await this.userProfileRepository.findOneAndRelations({
92
- where: { user: {
93
- id: user_id
94
- } },
95
- relations: ['user']
96
- });
97
- const uploadedFile = await this.uploadService.uploadImage(avatar, user_id, UploadEnum_1.UploadDirectories.USERS, "UserProfileModel");
98
- logger_1.logger.info("User avatar successfully created");
99
- if (!existingProfile) {
100
- await this.userProfileRepository.create({ profile_image_id: uploadedFile.id, user_id });
101
- }
102
- else {
103
- await this.userProfileRepository.updateOne({ user_id }, { profile_image_id: uploadedFile.id });
104
- }
105
- logger_1.logger.debug(messages_1.dynamic_messages.SUCCESSFULLY_UPDATED("Profile image"));
106
- return {
107
- successful: true,
108
- data: null,
109
- message: messages_1.dynamic_messages.SUCCESSFULLY_UPDATED("Profile image"),
110
- };
111
- }
112
- async changeUserPassword(req, user_id) {
113
- const { new_password } = req;
114
- const password_hash = await (0, utils_1.hashString)(new_password);
115
- await this.userRepository.updateOne({ id: user_id }, { password_hash });
116
- logger_1.logger.debug(messages_1.dynamic_messages.SUCCESSFULLY_UPDATED("Password"));
117
- return {
118
- successful: true,
119
- data: null,
120
- message: messages_1.dynamic_messages.SUCCESSFULLY_UPDATED("Password"),
121
- };
122
- }
123
- };
124
- UserService = __decorate([
125
- (0, typedi_1.Service)(),
126
- __metadata("design:paramtypes", [])
127
- ], UserService);
128
- exports.default = UserService;