@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,640 +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 UploadService_1 = __importDefault(require("./UploadService"));
20
- const UploadEnum_1 = require("@/common/enums/UploadEnum");
21
- const PostRepository_1 = require("@/repositories/PostRepository");
22
- const PostImageRepository_1 = require("@/repositories/PostImageRepository");
23
- const PostCollection_1 = require("../../transformers/collections/PostCollection");
24
- const Paginator_1 = require("@/transformers/Paginator");
25
- const configs_1 = require("@/common/configs");
26
- const PostResource_1 = require("@/transformers/resources/PostResource");
27
- const CommunityMemberRepository_1 = require("@/repositories/CommunityMemberRepository");
28
- const CommunityRepository_1 = require("@/repositories/CommunityRepository");
29
- const LikeRepository_1 = require("@/repositories/LikeRepository");
30
- const IndexEnum_1 = require("@/common/enums/IndexEnum");
31
- const CommentModel_1 = __importDefault(require("@/models/CommentModel"));
32
- const LikeModel_1 = __importDefault(require("@/models/LikeModel"));
33
- const PostImageModel_1 = __importDefault(require("@/models/PostImageModel"));
34
- const TopicRepository_1 = require("@/repositories/TopicRepository");
35
- let PostService = class PostService {
36
- postRepository;
37
- uploadService;
38
- postImageRepository;
39
- communityMemberRepository;
40
- communityRepository;
41
- likeRepository;
42
- topicRepository;
43
- constructor() {
44
- this.postRepository = new PostRepository_1.PostRepository();
45
- this.uploadService = new UploadService_1.default();
46
- this.postImageRepository = new PostImageRepository_1.PostImageRepository();
47
- this.communityRepository = new CommunityRepository_1.CommunityRepository();
48
- this.communityMemberRepository = new CommunityMemberRepository_1.CommunityMemberRepository();
49
- this.likeRepository = new LikeRepository_1.LikeRepository();
50
- this.topicRepository = new TopicRepository_1.TopicRepository();
51
- }
52
- async createPost(postData, user_id) {
53
- let message;
54
- const { title, visibility, community_id, is_boosted, is_sensitive, post_images, description, } = postData;
55
- if (post_images && post_images?.length > 5) {
56
- message = "Maximum of 5 images allowed";
57
- logger_1.logger.error(message);
58
- throw new AppError_1.AppError(message, 422);
59
- }
60
- const community = await this.communityRepository.basicFindOneByConditions({
61
- uuid: community_id
62
- });
63
- if (!community) {
64
- message = messages_1.dynamic_messages.NOT_FOUND("Community");
65
- logger_1.logger.info(message);
66
- throw new AppError_1.AppError(message, 404);
67
- }
68
- const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
69
- community_id: community.id,
70
- member_id: user_id
71
- });
72
- if (!isCommunityMember) {
73
- message = `You must be a member of ${community.name} to be able to make a post!`;
74
- logger_1.logger.info(message);
75
- throw new AppError_1.AppError(message, 403);
76
- }
77
- const createdPost = await this.postRepository.create({
78
- title: title ?? null,
79
- visibility,
80
- is_boosted,
81
- is_sensitive,
82
- description,
83
- community_id: community.id,
84
- user_id
85
- });
86
- const postId = createdPost.id;
87
- logger_1.logger.info("Post created without cover image");
88
- if (post_images?.length) {
89
- const uploadedFiles = await Promise.all(post_images.map((post_image) => this.uploadService.uploadImage(post_image, postId, UploadEnum_1.UploadDirectories.COMMUNITY_POST_IMAGES, "PostModel")));
90
- await Promise.all(uploadedFiles.map((file) => this.postImageRepository.create({
91
- post_id: postId,
92
- image_id: file.id,
93
- })));
94
- }
95
- return {
96
- successful: true,
97
- data: {
98
- post: {
99
- created_at: createdPost.created_at
100
- }
101
- },
102
- message: "Post created successfully"
103
- };
104
- }
105
- async getOnePost(post_id, user_id) {
106
- let message;
107
- const foundPost = await this.postRepository.basicFindOneByConditions({
108
- uuid: post_id
109
- });
110
- if (!foundPost) {
111
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
112
- logger_1.logger.info(message);
113
- throw new AppError_1.AppError(message, 404);
114
- }
115
- const community = await this.communityRepository.basicFindOneByConditions({
116
- id: foundPost.community_id
117
- });
118
- if (!community) {
119
- message = "We couldn't find the community that owns the post you want see";
120
- logger_1.logger.info(message);
121
- throw new AppError_1.AppError(message, 404);
122
- }
123
- const qb = this.postRepository
124
- .getRepo()
125
- .createQueryBuilder("post")
126
- .leftJoin("post.user", "user")
127
- .leftJoin("post.community", "community")
128
- .where("post.deleted_at IS NULL")
129
- .andWhere("post.uuid = :postId", {
130
- postId: post_id,
131
- });
132
- /* ======================
133
- POST FIELDS
134
- ====================== */
135
- qb.select([
136
- "post.id",
137
- "post.uuid",
138
- "post.title",
139
- "post.description",
140
- "post.visibility",
141
- "post.is_boosted",
142
- "post.is_sensitive",
143
- "post.created_at",
144
- "user.id",
145
- "user.uuid",
146
- "user.full_name",
147
- "community.id",
148
- "community.uuid",
149
- "community.name",
150
- ]);
151
- // Check if the user is a member of the community
152
- qb.addSelect(`
153
- EXISTS (
154
- SELECT 1
155
- FROM community_members cm
156
- WHERE cm.community_id = post.community_id
157
- AND cm.member_id = :user_id
158
- AND cm.deleted_at IS NULL
159
- )
160
- `, "is_member").setParameter("user_id", user_id);
161
- // Check if the user has liked the post
162
- qb.addSelect(`
163
- EXISTS (
164
- SELECT 1
165
- FROM likes l
166
- WHERE l.likeable_id = post.id
167
- AND l.likeable_type = :postType
168
- AND l.user_id = :user_id
169
- AND l.deleted_at IS NULL
170
- )
171
- `, "has_liked")
172
- .setParameter("postType", IndexEnum_1.SYS_MODELS.POST_MODEL)
173
- .setParameter("user_id", user_id);
174
- /* ======================
175
- TOTAL COMMENTS COUNT
176
- ====================== */
177
- qb.addSelect(subQuery => {
178
- return subQuery
179
- .select("COUNT(c.id)")
180
- .from(CommentModel_1.default, "c")
181
- .where("c.post_id = post.id")
182
- .andWhere("c.deleted_at IS NULL");
183
- }, "comments_count");
184
- /* ======================
185
- TOTAL POST LIKES
186
- ====================== */
187
- qb.addSelect(subQuery => {
188
- return subQuery
189
- .select("COUNT(l.id)")
190
- .from(LikeModel_1.default, "l")
191
- .where("l.likeable_id = post.id")
192
- .andWhere("l.likeable_type = :postType");
193
- }, "likes_count")
194
- .setParameter("postType", IndexEnum_1.SYS_MODELS.POST_MODEL);
195
- /* ======================
196
- LAST 4 COMMENTS (WITH META)
197
- ====================== */
198
- qb.addSelect(subQuery => {
199
- return subQuery
200
- .select(`
201
- COALESCE(
202
- json_agg(
203
- json_build_object(
204
- 'id', c.c_id,
205
- 'uuid', c.c_uuid,
206
- 'content', c.c_content,
207
- 'created_at', c.c_created_at,
208
-
209
- 'user', json_build_object(
210
- 'id', c.u_id,
211
- 'uuid', c.u_uuid,
212
- 'full_name', c.u_full_name
213
- ),
214
-
215
- 'likes_count', (
216
- SELECT COUNT(*)
217
- FROM likes cl
218
- WHERE cl.likeable_id = c.c_id
219
- AND cl.likeable_type = '${IndexEnum_1.SYS_MODELS.POST_COMMENT_MODEL}'
220
- ),
221
-
222
- 'replies_count', (
223
- SELECT COUNT(*)
224
- FROM comments r
225
- WHERE r.parent_id = c.c_id
226
- AND r.deleted_at IS NULL
227
- )
228
- )
229
- ORDER BY c.c_created_at DESC
230
- ),
231
- '[]'
232
- )
233
- `)
234
- .from(qb2 => {
235
- return qb2
236
- .select([
237
- "c.id AS c_id",
238
- "c.uuid AS c_uuid",
239
- "c.created_at AS c_created_at",
240
- "c.content AS c_content",
241
- "u.id AS u_id",
242
- "u.uuid AS u_uuid",
243
- "u.full_name AS u_full_name",
244
- ])
245
- .from(CommentModel_1.default, "c")
246
- .leftJoin("c.user", "u")
247
- .where("c.post_id = post.id")
248
- .andWhere("c.parent_id IS NULL")
249
- .andWhere("c.deleted_at IS NULL")
250
- .orderBy("c.created_at", "DESC")
251
- .limit(4);
252
- }, "c");
253
- }, "last_comments");
254
- /* ======================
255
- IMAGES (JSON AGG)
256
- ====================== */
257
- qb.addSelect(subQuery => {
258
- return subQuery
259
- .select(`
260
- COALESCE(
261
- json_agg(
262
- json_build_object(
263
- 'id', pi.pi_id,
264
- 'uuid', pi.pi_uuid,
265
- 'file_name', pi.file_name,
266
- 'file_size', pi.file_size,
267
- 'file_mimetype', pi.file_mimetype,
268
- 'url', pi.url
269
- )
270
- ORDER BY pi.pi_created_at ASC
271
- ) FILTER (WHERE pi.pi_id IS NOT NULL),
272
- '[]'
273
- )
274
- `)
275
- .from(qb2 => {
276
- return qb2
277
- .select([
278
- "pi.id AS pi_id",
279
- "pi.uuid AS pi_uuid",
280
- "pi.created_at AS pi_created_at",
281
- "u.file_name AS file_name",
282
- "u.file_size AS file_size",
283
- "u.file_mimetype AS file_mimetype",
284
- "u.url AS url",
285
- ])
286
- .from(PostImageModel_1.default, "pi")
287
- .leftJoin("pi.upload", "u")
288
- .where("pi.post_id = post.id")
289
- .andWhere("pi.deleted_at IS NULL")
290
- .andWhere("u.deleted_at IS NULL");
291
- }, "pi");
292
- }, "images");
293
- /* ======================
294
- ORDERING
295
- ====================== */
296
- qb.orderBy("post.created_at", "DESC");
297
- /* ======================
298
- PAGINATION
299
- ====================== */
300
- const { entities, raw } = await qb.getRawAndEntities();
301
- const post = entities;
302
- if (!post[0] || !raw[0]) {
303
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
304
- logger_1.logger.info(message);
305
- throw new AppError_1.AppError(message, 404);
306
- }
307
- return {
308
- successful: true,
309
- data: PostResource_1.PostResource.toJSON(raw[0], post[0], user_id),
310
- message: "Post fetched successfully!"
311
- };
312
- }
313
- async getCommunitiesPostsByTopic(topic_id, user_id, pageNumber) {
314
- let message;
315
- const page_number = pageNumber || 1;
316
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
317
- const foundTopic = await this.topicRepository.getRepo().findOne({
318
- select: ['name', 'uuid', 'id'],
319
- where: { uuid: topic_id }
320
- });
321
- if (!foundTopic) {
322
- message = messages_1.dynamic_messages.NOT_FOUND("Topic");
323
- logger_1.logger.info(message);
324
- throw new AppError_1.AppError(message, 404);
325
- }
326
- const { data: posts, total, perPage, page } = await this.postRepository.getCommunitiesPostsByTopic({
327
- page_number,
328
- limit
329
- }, user_id, foundTopic.id);
330
- const { entities, raw } = posts;
331
- const postsData = (0, Paginator_1.paginator)({
332
- total: total,
333
- perPage: perPage,
334
- currentPage: page,
335
- data: PostCollection_1.PostCollection.toJSON(raw, entities),
336
- });
337
- return {
338
- successful: true,
339
- data: postsData,
340
- message: "posts fetched successfully!"
341
- };
342
- }
343
- async exploreCommunityPosts(user_id, pageNumber) {
344
- let message;
345
- const page_number = pageNumber || 1;
346
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
347
- const { data: posts, total, perPage, page } = await this.postRepository.getPageCommunityPosts({
348
- page_number,
349
- limit
350
- }, user_id);
351
- const { entities, raw } = posts;
352
- const postsData = (0, Paginator_1.paginator)({
353
- total: total,
354
- perPage: perPage,
355
- currentPage: page,
356
- data: PostCollection_1.PostCollection.toJSON(raw, entities),
357
- });
358
- return {
359
- successful: true,
360
- data: postsData,
361
- message: "posts fetched successfully!"
362
- };
363
- }
364
- async getTrendingPosts(user_id, pageNumber) {
365
- const page_number = pageNumber || 1;
366
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
367
- const { data: posts, total, perPage, page } = await this.postRepository.getPagedTrendingPosts({
368
- page_number,
369
- limit
370
- }, user_id);
371
- const { entities, raw } = posts;
372
- const postsData = (0, Paginator_1.paginator)({
373
- total: total,
374
- perPage: perPage,
375
- currentPage: page,
376
- data: PostCollection_1.PostCollection.toJSON(raw, entities),
377
- });
378
- return {
379
- successful: true,
380
- data: postsData,
381
- message: "Posts fetched successfully!"
382
- };
383
- }
384
- async getPosts(user_id, community_id, pageNumber) {
385
- let message;
386
- const page_number = pageNumber || 1;
387
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
388
- const community = await this.communityRepository.basicFindOneByConditions({
389
- uuid: community_id
390
- });
391
- if (!community) {
392
- message = messages_1.dynamic_messages.NOT_FOUND("Community");
393
- logger_1.logger.info(message);
394
- throw new AppError_1.AppError(message, 404);
395
- }
396
- const dataFetchParams = {
397
- page_number,
398
- limit,
399
- metadata: {
400
- community_id: community.id
401
- }
402
- };
403
- const posts = await this.loadPaginatedPosts(dataFetchParams, user_id);
404
- if (!posts) {
405
- message = messages_1.dynamic_messages.NOT_FOUND("posts");
406
- logger_1.logger.info(message);
407
- throw new AppError_1.AppError(message, 404);
408
- }
409
- return {
410
- successful: true,
411
- data: posts,
412
- message: "posts fetched successfully!"
413
- };
414
- }
415
- async loadPaginatedPosts(paginationDto, userId) {
416
- try {
417
- const { data, total, perPage, page } = await this.postRepository.getPagedPosts(paginationDto, userId);
418
- const { entities, raw } = data;
419
- return (0, Paginator_1.paginator)({
420
- total: total,
421
- perPage: perPage,
422
- currentPage: page,
423
- data: PostCollection_1.PostCollection.toJSON(raw, entities),
424
- });
425
- }
426
- catch (error) {
427
- logger_1.logger.error("Error loading messages:", {
428
- error: error.message,
429
- stack: error.stack,
430
- });
431
- throw error;
432
- }
433
- }
434
- async updateOnePost(postData, post_id, user_id) {
435
- let message;
436
- const { title, visibility, is_boosted, is_sensitive, description, } = postData;
437
- const post = await this.postRepository.basicFindOneByConditions({
438
- uuid: post_id,
439
- user_id
440
- });
441
- if (!post) {
442
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
443
- logger_1.logger.info(message);
444
- throw new AppError_1.AppError(message, 404);
445
- }
446
- const updatedPost = await this.postRepository.updateOne({
447
- uuid: post.uuid,
448
- user_id,
449
- }, {
450
- title: title ?? null,
451
- visibility,
452
- is_boosted,
453
- is_sensitive,
454
- description,
455
- });
456
- return {
457
- successful: true,
458
- data: updatedPost,
459
- message: "Post updated successfully!"
460
- };
461
- }
462
- async likeOrUnlikePost(post_id, user_id) {
463
- let message;
464
- const post = await this.postRepository.basicFindOneByConditions({
465
- uuid: post_id,
466
- user_id
467
- });
468
- if (!post) {
469
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
470
- logger_1.logger.info(message);
471
- throw new AppError_1.AppError(message, 404);
472
- }
473
- const community = await this.communityRepository.basicFindOneByConditions({
474
- id: post.community_id
475
- });
476
- if (!community) {
477
- message = "We couldn't find the community that owns the post you want to like or unlike";
478
- logger_1.logger.info(message);
479
- throw new AppError_1.AppError(message, 404);
480
- }
481
- const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
482
- community_id: community.id,
483
- member_id: user_id
484
- });
485
- if (!isCommunityMember) {
486
- message = `You must be a member of ${community.name} to be to like or unlike a post in it!`;
487
- logger_1.logger.info(message);
488
- throw new AppError_1.AppError(message, 403);
489
- }
490
- const alreadyLikedPost = await this.likeRepository.basicFindOneByConditions({
491
- likeable_id: post.id,
492
- likeable_type: IndexEnum_1.SYS_MODELS.POST_MODEL,
493
- user_id
494
- });
495
- if (alreadyLikedPost) {
496
- // Unlike the post
497
- await this.likeRepository.deleteByCondition({
498
- user_id,
499
- likeable_id: post.id,
500
- likeable_type: IndexEnum_1.SYS_MODELS.POST_MODEL
501
- });
502
- message = "Post unliked successfully";
503
- }
504
- else {
505
- // Like the post
506
- await this.likeRepository.create({
507
- user_id,
508
- likeable_id: post.id,
509
- likeable_type: IndexEnum_1.SYS_MODELS.POST_MODEL
510
- });
511
- message = "Post liked successfully";
512
- }
513
- return {
514
- successful: true,
515
- data: null,
516
- message
517
- };
518
- }
519
- async deleteOnePost(post_id, user_id) {
520
- let message;
521
- const post = await this.postRepository.basicFindOneByConditions({
522
- uuid: post_id,
523
- user_id
524
- });
525
- if (!post) {
526
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
527
- logger_1.logger.info(message);
528
- throw new AppError_1.AppError(message, 404);
529
- }
530
- const postUploads = await this.postImageRepository.basicFindManyByConditions({
531
- post_id: post.id
532
- });
533
- if (postUploads?.length) {
534
- await Promise.all(postUploads.map((post_image) => this.uploadService.deleteFile(post_image.image_id, post_image?.post_id, "image")));
535
- await this.postImageRepository.deleteByCondition({ post_id: post.id });
536
- }
537
- await this.postRepository.deleteByCondition({
538
- uuid: post.uuid,
539
- user_id,
540
- });
541
- return {
542
- successful: true,
543
- data: null,
544
- message: "Post deleted successfully!"
545
- };
546
- }
547
- async deletePostUpload(post_id, post_image_id, user_id) {
548
- let message;
549
- const post = await this.postRepository.basicFindOneByConditions({
550
- uuid: post_id,
551
- user_id
552
- });
553
- if (!post) {
554
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
555
- logger_1.logger.info(message);
556
- throw new AppError_1.AppError(message, 404);
557
- }
558
- const postUpload = await this.postImageRepository.basicFindOneByConditions({
559
- post_id: post.id,
560
- uuid: post_image_id
561
- });
562
- if (!postUpload) {
563
- message = messages_1.dynamic_messages.NOT_FOUND("Post File");
564
- logger_1.logger.info(message);
565
- throw new AppError_1.AppError(message, 404);
566
- }
567
- this.uploadService.deleteFile(postUpload.image_id, postUpload?.post_id, "image");
568
- await this.postImageRepository.deleteByCondition({ post_id: post.id });
569
- return {
570
- successful: true,
571
- data: null,
572
- message: "Post image deleted successfully!"
573
- };
574
- }
575
- async getUserThatLikedPost(post_id, user_id, pageNumber) {
576
- let message;
577
- const post = await this.postRepository.basicFindOneByConditions({
578
- uuid: post_id
579
- });
580
- if (!post) {
581
- message = messages_1.dynamic_messages.NOT_FOUND("Post");
582
- logger_1.logger.info(message);
583
- throw new AppError_1.AppError(message, 404);
584
- }
585
- const community = await this.communityRepository.basicFindOneByConditions({
586
- id: post.community_id
587
- });
588
- if (!community) {
589
- message = "We couldn't find the community that owns the post";
590
- logger_1.logger.info(message);
591
- throw new AppError_1.AppError(message, 404);
592
- }
593
- const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
594
- community_id: community.id,
595
- member_id: user_id
596
- });
597
- if (!isCommunityMember) {
598
- message = `You must be a member of ${community.name} community to continue!`;
599
- logger_1.logger.info(message);
600
- throw new AppError_1.AppError(message, 403);
601
- }
602
- const page_number = pageNumber || 1;
603
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
604
- const dataFetchParams = {
605
- page_number,
606
- limit,
607
- metadata: {
608
- post_id: post.id
609
- }
610
- };
611
- const { data, total, perPage, page } = await this.likeRepository.getPagedPostsUserLikes(dataFetchParams, user_id);
612
- const { entities, raw } = data;
613
- const postUserLikes = raw.map((like) => {
614
- return {
615
- user: {
616
- name: like?.user_full_name,
617
- uuid: like?.user_uuid,
618
- avatar_url: like?.avatar_url,
619
- },
620
- liked_at: like?.like_created_at
621
- };
622
- });
623
- const postLikes = (0, Paginator_1.paginator)({
624
- total: total,
625
- perPage: perPage,
626
- currentPage: page,
627
- data: postUserLikes,
628
- });
629
- return {
630
- successful: true,
631
- data: postLikes,
632
- message: "User likes fetched successfully!"
633
- };
634
- }
635
- };
636
- PostService = __decorate([
637
- (0, typedi_1.Service)(),
638
- __metadata("design:paramtypes", [])
639
- ], PostService);
640
- exports.default = PostService;