@aurispec/core-backend 1.0.3 → 1.0.5

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/common/configs/cloudinary.d.ts +1 -1
  2. package/dist/common/configs/cloudinary.d.ts.map +1 -1
  3. package/dist/common/configs/cloudinary.js +2 -1
  4. package/dist/common/utils/index.d.ts +5 -0
  5. package/dist/common/utils/index.d.ts.map +1 -1
  6. package/dist/common/utils/index.js +16 -0
  7. package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts +7 -0
  8. package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts.map +1 -0
  9. package/dist/database/migrations/1772984882048-modified_reviews_table.js +61 -0
  10. package/dist/models/BusinessModel.d.ts +2 -0
  11. package/dist/models/BusinessModel.d.ts.map +1 -1
  12. package/dist/models/BusinessModel.js +9 -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 +19 -0
  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,561 +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 CommunityRepository_1 = require("@/repositories/CommunityRepository");
22
- const TopicRepository_1 = require("@/repositories/TopicRepository");
23
- const CommunityTopicRepository_1 = require("@/repositories/CommunityTopicRepository");
24
- const CommunityMemberRepository_1 = require("@/repositories/CommunityMemberRepository");
25
- const CommunityEnum_1 = require("@/common/enums/CommunityEnum");
26
- const Paginator_1 = require("@/transformers/Paginator");
27
- const configs_1 = require("@/common/configs");
28
- const CommunityResource_1 = require("@/transformers/resources/CommunityResource");
29
- const CommunityMemberModel_1 = __importDefault(require("@/models/CommunityMemberModel"));
30
- const PostModel_1 = __importDefault(require("@/models/PostModel"));
31
- const CommunityTopicModel_1 = __importDefault(require("@/models/CommunityTopicModel"));
32
- let CommunityService = class CommunityService {
33
- communityRepository;
34
- uploadService;
35
- topicRepository;
36
- communityTopicRepository;
37
- communityMemberRepository;
38
- constructor() {
39
- this.communityRepository = new CommunityRepository_1.CommunityRepository();
40
- this.topicRepository = new TopicRepository_1.TopicRepository();
41
- this.uploadService = new UploadService_1.default();
42
- this.communityTopicRepository = new CommunityTopicRepository_1.CommunityTopicRepository();
43
- this.communityMemberRepository = new CommunityMemberRepository_1.CommunityMemberRepository();
44
- }
45
- async createCommunity(communityData, user_id) {
46
- let message;
47
- const { name, visibility, topics, cover_image, profile_image, description, } = communityData;
48
- let foundTopics = [];
49
- let createdTopics = [];
50
- topics?.map(async (topic) => {
51
- if (!topic) {
52
- message = "Topic is required!";
53
- logger_1.logger.info(message);
54
- throw new AppError_1.AppError(message, 404);
55
- }
56
- const foundTopic = await this.topicRepository.getRepo().findOne({
57
- select: ['name', 'uuid', 'id'],
58
- where: {
59
- uuid: topic
60
- }
61
- });
62
- if (!foundTopic) {
63
- message = messages_1.dynamic_messages.NOT_FOUND("Topic");
64
- logger_1.logger.info(message);
65
- throw new AppError_1.AppError(message, 404);
66
- }
67
- foundTopics.push(foundTopic.id);
68
- createdTopics.push(foundTopic);
69
- });
70
- const createdCommunity = await this.communityRepository.create({
71
- name,
72
- description,
73
- visibility,
74
- user_id
75
- });
76
- const communityId = createdCommunity.id;
77
- logger_1.logger.info("Community created without cover image");
78
- if (profile_image) {
79
- const uploadedProfileImageFile = await this.uploadService.uploadImage(profile_image, communityId, UploadEnum_1.UploadDirectories.COMMUNITY_PROFILE_IMAGES, "CommunityModel");
80
- await this.communityRepository.updateOne({
81
- uuid: createdCommunity.uuid,
82
- user_id,
83
- }, {
84
- profile_image_id: uploadedProfileImageFile.id,
85
- });
86
- logger_1.logger.info("Community profile image added successfully");
87
- }
88
- if (cover_image) {
89
- const uploadedCoverImageFile = await this.uploadService.uploadImage(cover_image, communityId, UploadEnum_1.UploadDirectories.COMMUNITY_COVER_IMAGES, "CommunityModel");
90
- logger_1.logger.info("Community cover image successfully created");
91
- await this.communityRepository.updateOne({
92
- uuid: createdCommunity.uuid,
93
- user_id,
94
- }, {
95
- cover_image_id: uploadedCoverImageFile.id,
96
- });
97
- logger_1.logger.info("Community cover image added successfully");
98
- }
99
- foundTopics.map(async (topic) => {
100
- await this.communityTopicRepository.create({
101
- community_id: communityId,
102
- topic_id: topic,
103
- });
104
- });
105
- await this.communityMemberRepository.create({
106
- community_id: communityId,
107
- member_id: user_id,
108
- role: CommunityEnum_1.CommunityRole.OWNER
109
- });
110
- return {
111
- successful: true,
112
- data: {
113
- community_id: createdCommunity.uuid,
114
- topics: createdTopics,
115
- },
116
- message: "Community created successfully"
117
- };
118
- }
119
- async getCommunityCreationData() {
120
- const topics = await this.topicRepository.getRepo().find({
121
- select: ['name', 'uuid']
122
- });
123
- return {
124
- successful: true,
125
- data: {
126
- topics
127
- },
128
- message: "Community creation data fetched successfully!"
129
- };
130
- }
131
- async getOneCommunity(community_id, user_id) {
132
- let message;
133
- const qb = this.communityRepository
134
- .getRepo()
135
- .createQueryBuilder("community")
136
- /* BASE COMMUNITY QUERY LOGIC */
137
- .leftJoinAndSelect("community.user", "user")
138
- .leftJoinAndSelect("community.cover_image", "cover_image")
139
- .leftJoinAndSelect("community.profile_image", "profile_image")
140
- .where("community.deleted_at IS NULL")
141
- .andWhere("community.uuid = :community_id", {
142
- community_id,
143
- });
144
- /* ======================
145
- SELECT FIELDS (SAFE)
146
- ====================== */
147
- qb.select([
148
- "community.uuid",
149
- "community.id",
150
- "community.name",
151
- "community.description",
152
- "community.visibility",
153
- "community.created_at",
154
- "user.uuid",
155
- "user.full_name",
156
- "cover_image.uuid",
157
- "cover_image.url",
158
- "profile_image.uuid",
159
- "profile_image.url",
160
- ]);
161
- /* MEMBERS COUNT */
162
- qb.addSelect(subQuery => {
163
- return subQuery
164
- .select("COUNT(community_member.id)", "count")
165
- .from(CommunityMemberModel_1.default, "community_member")
166
- .where("community_member.community_id = community.id");
167
- }, "members_count");
168
- /* NEW MEMBERS COUNT */
169
- qb.addSelect(subQuery => {
170
- return subQuery
171
- .select(`
172
- COUNT(
173
- CASE
174
- WHEN cm.created_at >= (
175
- date_trunc('week', now() + interval '1 day') - interval '1 day'
176
- )
177
- THEN 1
178
- END
179
- )
180
- `)
181
- .from(CommunityMemberModel_1.default, "cm")
182
- .where("cm.community_id = community.id")
183
- .andWhere("cm.deleted_at IS NULL");
184
- }, "new_members_this_week");
185
- /* POSTS COUNT */
186
- qb.addSelect(subQuery => {
187
- return subQuery
188
- .select("COUNT(post.id)", "count")
189
- .from(PostModel_1.default, "post")
190
- .where("post.community_id = community.id");
191
- }, "posts_count");
192
- /* 4 TOPICS */
193
- qb.addSelect(subQuery => {
194
- return subQuery
195
- .select(`
196
- json_agg(
197
- json_build_object(
198
- 'id', topic.id,
199
- 'name', topic.name
200
- )
201
- )
202
- `)
203
- .from(CommunityTopicModel_1.default, "ct")
204
- .leftJoin("ct.community_topic", "topic")
205
- .where("ct.community_id = community.id")
206
- .limit(4);
207
- }, "community_topics");
208
- /* LAST 4 MEMBERS + USER DETAILS */
209
- qb.addSelect(subQuery => {
210
- return subQuery
211
- .select(`
212
- json_agg(
213
- json_build_object(
214
- 'id', cm.member_id,
215
- 'joined_at', cm.joined_at,
216
- 'role', cm.role,
217
- 'user', json_build_object(
218
- 'id', cm.user_id,
219
- 'uuid', cm.user_uuid,
220
- 'full_name', cm.user_full_name
221
- )
222
- )
223
- )
224
- `)
225
- .from(qb2 => {
226
- return qb2
227
- .select([
228
- "cm.id AS member_id",
229
- "cm.created_at AS joined_at",
230
- "cm.role AS role",
231
- "u.id AS user_id",
232
- "u.uuid AS user_uuid",
233
- "u.full_name AS user_full_name",
234
- ])
235
- .from(CommunityMemberModel_1.default, "cm")
236
- .leftJoin("cm.member", "u")
237
- .where("cm.community_id = community.id")
238
- .andWhere("cm.deleted_at IS NULL")
239
- .orderBy("cm.created_at", "DESC")
240
- .limit(4);
241
- }, "cm");
242
- }, "last_members");
243
- /* ---------- DATA QUERY ---------- */
244
- const { entities, raw } = await qb.getRawAndEntities();
245
- const community = entities;
246
- const { uuid, visibility, name, description, cover_image, profile_image, created_at, user } = community[0];
247
- const { members_count, new_members_this_week, posts_count, community_topics, last_members } = raw[0];
248
- const data = {
249
- uuid,
250
- visibility,
251
- name,
252
- description,
253
- cover_image: cover_image?.url,
254
- profile_image: profile_image?.url,
255
- created_at,
256
- created_by: {
257
- uuid: user?.uuid,
258
- full_name: user?.full_name,
259
- },
260
- members_count,
261
- owned_by_me: user_id === user?.id,
262
- new_members_this_week,
263
- posts_count,
264
- community_topics,
265
- last_members,
266
- };
267
- if (!community[0]) {
268
- message = messages_1.dynamic_messages.NOT_FOUND("Community");
269
- logger_1.logger.info(message);
270
- throw new AppError_1.AppError(message, 404);
271
- }
272
- return {
273
- successful: true,
274
- data,
275
- message: "Community fetched successfully!"
276
- };
277
- }
278
- async getCommunities(user_id, pageNumber) {
279
- let message;
280
- const page_number = pageNumber || 1;
281
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
282
- const dataFetchParams = {
283
- page_number,
284
- limit,
285
- };
286
- const communities = await this.loadPaginatedCommunities(dataFetchParams, user_id);
287
- if (!communities) {
288
- message = messages_1.dynamic_messages.NOT_FOUND("communities");
289
- logger_1.logger.info(message);
290
- throw new AppError_1.AppError(message, 404);
291
- }
292
- return {
293
- successful: true,
294
- data: communities,
295
- message: "communities fetched successfully!"
296
- };
297
- }
298
- async recommendedCommunities(user_id, pageNumber) {
299
- let message;
300
- const page_number = pageNumber || 1;
301
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
302
- const dataFetchParams = {
303
- page_number,
304
- limit,
305
- metadata: {
306
- user_id,
307
- recommendation: true
308
- }
309
- };
310
- const communities = await this.loadPaginatedCommunities(dataFetchParams, user_id);
311
- if (!communities) {
312
- message = messages_1.dynamic_messages.NOT_FOUND("communities");
313
- logger_1.logger.info(message);
314
- throw new AppError_1.AppError(message, 404);
315
- }
316
- return {
317
- successful: true,
318
- data: communities,
319
- message: "communities fetched successfully!"
320
- };
321
- }
322
- // public async getRecommendedCommunities(user_id: number, pageNumber?: number):
323
- // Promise<ServiceResponseDTO> {
324
- // let message;
325
- // const page_number = pageNumber || 1;
326
- // const data_fetch_limit = CONFIGS.DATA_FETCH_LIMIT || 10;
327
- // const limit = (page_number - 1) * data_fetch_limit;
328
- // const userRepository = new UserRepository();
329
- // const existingUser = await userRepository.findOneAndRelations({
330
- // where: {
331
- // id: user_id
332
- // },
333
- // relations: ['user_profile']
334
- // });
335
- // if (!existingUser) {
336
- // const message = dynamic_messages.NOT_FOUND("User");
337
- // logger.info(message)
338
- // throw new AppError(message)
339
- // }
340
- // const location = existingUser?.user_profile?.location;
341
- // const recommendationOptions: RecommendationOptions = {
342
- // page_number,
343
- // limit,
344
- // user_id,
345
- // lat: location?.coordinates?.lat,
346
- // lng: location?.coordinates?.long,
347
- // city: location?.city,
348
- // state: location?.state,
349
- // country: location?.country,
350
- // connections: [],
351
- // };
352
- // const communities = await this.recommendCommunities(recommendationOptions)
353
- // return {
354
- // successful: true,
355
- // data: communities,
356
- // message: "communities fetched successfully!"
357
- // };
358
- // }
359
- async loadPaginatedCommunities(paginationDto, userId) {
360
- let message;
361
- try {
362
- const { data, total, perPage, page } = await this.communityRepository.getPagedCommunityData(paginationDto, userId);
363
- const { entities, raw } = data;
364
- const communityEntities = entities;
365
- const rawCommunities = raw;
366
- if (!communityEntities || !rawCommunities) {
367
- message = messages_1.dynamic_messages.NOT_FOUND("Communities");
368
- logger_1.logger.info(message);
369
- throw new AppError_1.AppError(message, 404);
370
- }
371
- const communityCollections = communityEntities.map((communityEntity, index) => {
372
- const { uuid, visibility, created_at, name, description, user } = communityEntity;
373
- return {
374
- uuid,
375
- created_at,
376
- name,
377
- visibility,
378
- description,
379
- creator: {
380
- uuid: user?.uuid,
381
- full_name: user?.full_name,
382
- avatar_url: rawCommunities[index]?.creator_avatar_url,
383
- },
384
- community_cover_image_url: rawCommunities[index]?.cover_image_url,
385
- community_profile_image_url: rawCommunities[index]?.profile_image_url,
386
- members_count: rawCommunities[index]?.members_count,
387
- new_members_this_week: rawCommunities[index]?.new_members_this_week,
388
- community_topics: rawCommunities[index]?.community_topics,
389
- posts_count: rawCommunities[index]?.posts_count,
390
- last_members: rawCommunities[index]?.last_members,
391
- };
392
- });
393
- return (0, Paginator_1.paginator)({
394
- total,
395
- perPage,
396
- currentPage: page,
397
- data: communityCollections
398
- });
399
- }
400
- catch (error) {
401
- logger_1.logger.error("Error loading communities:", {
402
- error: error.message,
403
- stack: error.stack,
404
- });
405
- throw error;
406
- }
407
- }
408
- async updateOneCommunity(communityData, community_id, user_id) {
409
- let message;
410
- const { name, visibility, topics, cover_image, profile_image, description, } = communityData;
411
- let foundTopics = [];
412
- let optionalFieldsToUpdate = {};
413
- const community = await this.communityRepository.basicFindOneByConditions({
414
- uuid: community_id,
415
- user_id
416
- });
417
- if (!community) {
418
- message = messages_1.dynamic_messages.NOT_FOUND("Community");
419
- logger_1.logger.info(message);
420
- throw new AppError_1.AppError(message, 404);
421
- }
422
- topics?.map(async (topic) => {
423
- if (!topic) {
424
- message = "Topic is required!";
425
- logger_1.logger.info(message);
426
- throw new AppError_1.AppError(message, 404);
427
- }
428
- const foundTopic = await this.topicRepository.getRepo().findOne({
429
- select: ['name', 'uuid', 'id'],
430
- where: {
431
- uuid: topic
432
- }
433
- });
434
- if (!foundTopic) {
435
- message = messages_1.dynamic_messages.NOT_FOUND("Topic");
436
- logger_1.logger.info(message);
437
- throw new AppError_1.AppError(message, 404);
438
- }
439
- foundTopics.push(foundTopic.id);
440
- });
441
- if (cover_image) {
442
- await this.uploadService.deleteFile(community?.cover_image_id, community?.id, "image");
443
- const uploadedCoverImageFile = await this.uploadService.uploadImage(cover_image, community?.id, UploadEnum_1.UploadDirectories.COMMUNITY_COVER_IMAGES, "CommunityModel");
444
- optionalFieldsToUpdate.cover_image_id = uploadedCoverImageFile.id;
445
- }
446
- if (profile_image) {
447
- await this.uploadService.deleteFile(community?.profile_image_id, community?.id, "image");
448
- const uploadedProfileImageFile = await this.uploadService.uploadImage(profile_image, community?.id, UploadEnum_1.UploadDirectories.COMMUNITY_PROFILE_IMAGES, "CommunityModel");
449
- optionalFieldsToUpdate.profile_image_id = uploadedProfileImageFile.id;
450
- }
451
- await this.communityRepository.updateOne({
452
- uuid: community.uuid,
453
- user_id,
454
- }, {
455
- name,
456
- description,
457
- visibility,
458
- ...optionalFieldsToUpdate,
459
- });
460
- await this.communityTopicRepository.deleteByCondition({
461
- community_id: community.id
462
- });
463
- foundTopics.map(async (topic) => {
464
- await this.communityTopicRepository.create({
465
- community_id: community.id,
466
- topic_id: topic,
467
- });
468
- });
469
- return {
470
- successful: true,
471
- data: CommunityResource_1.CommunityResource.toJSON(community),
472
- message: "Community updated successfully!"
473
- };
474
- }
475
- async deleteOneCommunity(community_id, user_id) {
476
- let message;
477
- const community = await this.communityRepository.basicFindOneByConditions({
478
- uuid: community_id,
479
- user_id
480
- });
481
- if (!community) {
482
- message = messages_1.dynamic_messages.NOT_FOUND("Community");
483
- logger_1.logger.info(message);
484
- throw new AppError_1.AppError(message, 404);
485
- }
486
- if (community.user_id === user_id) {
487
- message = `You cannot delete a community you didn't create`;
488
- logger_1.logger.info(message);
489
- throw new AppError_1.AppError(message, 403);
490
- }
491
- await this.uploadService.deleteFile(community?.cover_image_id, community?.id, "image");
492
- await this.uploadService.deleteFile(community?.profile_image_id, community?.id, "image");
493
- await this.communityTopicRepository.deleteByCondition({
494
- community_id: community.id
495
- });
496
- await this.communityMemberRepository.deleteByCondition({
497
- community_id: community.id
498
- });
499
- await this.communityRepository.deleteByCondition({
500
- uuid: community.uuid,
501
- user_id,
502
- });
503
- return {
504
- successful: true,
505
- data: null,
506
- message: "Community deleted successfully!"
507
- };
508
- }
509
- async searchCommunities(search_string, user_id, pageNumber) {
510
- let message;
511
- const page_number = pageNumber || 1;
512
- const data_fetch_limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
513
- const limit = (page_number - 1) * data_fetch_limit;
514
- const dataFetchParams = {
515
- page_number,
516
- limit,
517
- metadata: {
518
- search_string
519
- }
520
- };
521
- const communities = await this.loadPaginatedCommunities(dataFetchParams, user_id);
522
- if (!communities) {
523
- message = messages_1.dynamic_messages.NOT_FOUND("communities");
524
- logger_1.logger.info(message);
525
- throw new AppError_1.AppError(message, 404);
526
- }
527
- return {
528
- successful: true,
529
- data: communities,
530
- message: "communities fetched successfully!"
531
- };
532
- }
533
- async communitiesIOwn(user_id, pageNumber) {
534
- let message;
535
- const page_number = pageNumber || 1;
536
- const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
537
- const dataFetchParams = {
538
- page_number,
539
- limit,
540
- metadata: {
541
- user_id
542
- }
543
- };
544
- const communities = await this.loadPaginatedCommunities(dataFetchParams, user_id);
545
- if (!communities) {
546
- message = messages_1.dynamic_messages.NOT_FOUND("communities");
547
- logger_1.logger.info(message);
548
- throw new AppError_1.AppError(message, 404);
549
- }
550
- return {
551
- successful: true,
552
- data: communities,
553
- message: "My communities fetched successfully!"
554
- };
555
- }
556
- };
557
- CommunityService = __decorate([
558
- (0, typedi_1.Service)(),
559
- __metadata("design:paramtypes", [])
560
- ], CommunityService);
561
- exports.default = CommunityService;