@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.
- package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts +7 -0
- package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts.map +1 -0
- package/dist/database/migrations/1772984882048-modified_reviews_table.js +61 -0
- package/dist/database/migrations/1773052871526-modified_categories_table.d.ts +7 -0
- package/dist/database/migrations/1773052871526-modified_categories_table.d.ts.map +1 -0
- package/dist/database/migrations/1773052871526-modified_categories_table.js +19 -0
- package/dist/models/BusinessModel.d.ts +2 -0
- package/dist/models/BusinessModel.d.ts.map +1 -1
- package/dist/models/BusinessModel.js +9 -0
- package/dist/models/CategoryModel.d.ts +2 -0
- package/dist/models/CategoryModel.d.ts.map +1 -1
- package/dist/models/CategoryModel.js +10 -0
- package/dist/models/ReviewModel.d.ts +5 -0
- package/dist/models/ReviewModel.d.ts.map +1 -1
- package/dist/models/ReviewModel.js +20 -1
- package/dist/models/UserModel.d.ts +2 -0
- package/dist/models/UserModel.d.ts.map +1 -1
- package/dist/models/UserModel.js +9 -0
- package/package.json +1 -1
- package/dist/app.js +0 -59
- package/dist/common/configs/express.js +0 -29
- package/dist/common/configs/websocket.js +0 -17
- package/dist/common/constants/chat.d.ts +0 -18
- package/dist/common/constants/chat.d.ts.map +0 -1
- package/dist/common/constants/chat.js +0 -20
- package/dist/common/constants/messages/admin.messages.d.ts +0 -33
- package/dist/common/constants/messages/admin.messages.d.ts.map +0 -1
- package/dist/common/constants/messages/admin.messages.js +0 -35
- package/dist/common/constants/messages/user.messages.d.ts +0 -33
- package/dist/common/constants/messages/user.messages.d.ts.map +0 -1
- package/dist/common/constants/messages/user.messages.js +0 -35
- package/dist/common/dtos/AdminDto.d.ts +0 -5
- package/dist/common/dtos/AdminDto.d.ts.map +0 -1
- package/dist/common/dtos/AdminDto.js +0 -30
- package/dist/common/dtos/ArticleDto.d.ts +0 -11
- package/dist/common/dtos/ArticleDto.d.ts.map +0 -1
- package/dist/common/dtos/ArticleDto.js +0 -61
- package/dist/common/dtos/BusinessDto.d.ts +0 -12
- package/dist/common/dtos/BusinessDto.d.ts.map +0 -1
- package/dist/common/dtos/BusinessDto.js +0 -59
- package/dist/common/dtos/ChatDto.d.ts +0 -17
- package/dist/common/dtos/ChatDto.d.ts.map +0 -1
- package/dist/common/dtos/ChatDto.js +0 -89
- package/dist/common/dtos/CommonDto.d.ts +0 -13
- package/dist/common/dtos/CommonDto.d.ts.map +0 -1
- package/dist/common/dtos/CommonDto.js +0 -59
- package/dist/common/dtos/CommunityDto.d.ts +0 -10
- package/dist/common/dtos/CommunityDto.d.ts.map +0 -1
- package/dist/common/dtos/CommunityDto.js +0 -72
- package/dist/common/dtos/EventDto.d.ts +0 -24
- package/dist/common/dtos/EventDto.d.ts.map +0 -1
- package/dist/common/dtos/EventDto.js +0 -72
- package/dist/common/dtos/IPaginator.d.ts +0 -15
- package/dist/common/dtos/IPaginator.d.ts.map +0 -1
- package/dist/common/dtos/IPaginator.js +0 -40
- package/dist/common/dtos/Plan.dto.d.ts +0 -10
- package/dist/common/dtos/Plan.dto.d.ts.map +0 -1
- package/dist/common/dtos/Plan.dto.js +0 -66
- package/dist/common/dtos/PostDto.d.ts +0 -13
- package/dist/common/dtos/PostDto.d.ts.map +0 -1
- package/dist/common/dtos/PostDto.js +0 -75
- package/dist/common/dtos/ProductDto.d.ts +0 -13
- package/dist/common/dtos/ProductDto.d.ts.map +0 -1
- package/dist/common/dtos/ProductDto.js +0 -66
- package/dist/common/dtos/ServiceDto.d.ts +0 -19
- package/dist/common/dtos/ServiceDto.d.ts.map +0 -1
- package/dist/common/dtos/ServiceDto.js +0 -93
- package/dist/common/dtos/UserDto.d.ts +0 -70
- package/dist/common/dtos/UserDto.d.ts.map +0 -1
- package/dist/common/dtos/UserDto.js +0 -313
- package/dist/common/types/IPagination.d.ts +0 -15
- package/dist/common/types/IPagination.d.ts.map +0 -1
- package/dist/common/types/IPagination.js +0 -2
- package/dist/common/utils/axios.js +0 -26
- package/dist/common/utils/socket.js +0 -16
- package/dist/database/seeds/CommunityDataSeeder.js +0 -48
- package/dist/database/seeds/EventDataSeeder.js +0 -54
- package/dist/database/seeds/FeatureSeeder.js +0 -131
- package/dist/database/seeds/MarketplaceDataSeeder.js +0 -95
- package/dist/database/seeds/PlanSeeder.js +0 -78
- package/dist/database/seeds/UserProfileDataSeeder.js +0 -215
- package/dist/database/seeds/index.js +0 -39
- package/dist/services/StripeService.js +0 -288
- package/dist/services/mobile/ArticleCommentService.js +0 -479
- package/dist/services/mobile/ArticleService.js +0 -507
- package/dist/services/mobile/AuthService.js +0 -362
- package/dist/services/mobile/BusinessService.js +0 -267
- package/dist/services/mobile/BusinessServiceService.js +0 -383
- package/dist/services/mobile/CardService.js +0 -249
- package/dist/services/mobile/ChatService.js +0 -324
- package/dist/services/mobile/CommunityMemberService.js +0 -193
- package/dist/services/mobile/CommunityService.js +0 -561
- package/dist/services/mobile/CompleteProfileService.js +0 -308
- package/dist/services/mobile/ConnectionService.js +0 -338
- package/dist/services/mobile/EventAttendanceService.js +0 -343
- package/dist/services/mobile/EventService.js +0 -540
- package/dist/services/mobile/NotificationService.js +0 -89
- package/dist/services/mobile/PasswordResetService.js +0 -168
- package/dist/services/mobile/PlanService.js +0 -85
- package/dist/services/mobile/PostCommentService.js +0 -611
- package/dist/services/mobile/PostService.js +0 -640
- package/dist/services/mobile/ProductService.js +0 -360
- package/dist/services/mobile/RedisService.js +0 -16
- package/dist/services/mobile/TransactionService.js +0 -51
- package/dist/services/mobile/UploadService.js +0 -110
- package/dist/services/mobile/UserService.js +0 -128
|
@@ -1,611 +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 PostRepository_1 = require("@/repositories/PostRepository");
|
|
20
|
-
const Paginator_1 = require("@/transformers/Paginator");
|
|
21
|
-
const configs_1 = require("@/common/configs");
|
|
22
|
-
const CommunityMemberRepository_1 = require("@/repositories/CommunityMemberRepository");
|
|
23
|
-
const CommunityRepository_1 = require("@/repositories/CommunityRepository");
|
|
24
|
-
const PostCommentRepository_1 = require("@/repositories/PostCommentRepository");
|
|
25
|
-
const PostCommentResource_1 = require("@/transformers/resources/PostCommentResource");
|
|
26
|
-
const IndexEnum_1 = require("@/common/enums/IndexEnum");
|
|
27
|
-
const LikeRepository_1 = require("@/repositories/LikeRepository");
|
|
28
|
-
const CommentModel_1 = __importDefault(require("@/models/CommentModel"));
|
|
29
|
-
const LikeModel_1 = __importDefault(require("@/models/LikeModel"));
|
|
30
|
-
let PostCommentService = class PostCommentService {
|
|
31
|
-
postRepository;
|
|
32
|
-
postCommentRepository;
|
|
33
|
-
communityMemberRepository;
|
|
34
|
-
communityRepository;
|
|
35
|
-
likeRepository;
|
|
36
|
-
constructor() {
|
|
37
|
-
this.postRepository = new PostRepository_1.PostRepository();
|
|
38
|
-
this.likeRepository = new LikeRepository_1.LikeRepository();
|
|
39
|
-
this.communityRepository = new CommunityRepository_1.CommunityRepository();
|
|
40
|
-
this.communityMemberRepository = new CommunityMemberRepository_1.CommunityMemberRepository();
|
|
41
|
-
this.postCommentRepository = new PostCommentRepository_1.PostCommentRepository();
|
|
42
|
-
}
|
|
43
|
-
async createPostComment(postCommentData, user_id, post_id) {
|
|
44
|
-
let message;
|
|
45
|
-
const { content, } = postCommentData;
|
|
46
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
47
|
-
uuid: post_id
|
|
48
|
-
});
|
|
49
|
-
if (!post) {
|
|
50
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Post");
|
|
51
|
-
logger_1.logger.info(message);
|
|
52
|
-
throw new AppError_1.AppError(message, 404);
|
|
53
|
-
}
|
|
54
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
55
|
-
id: post.community_id
|
|
56
|
-
});
|
|
57
|
-
if (!community) {
|
|
58
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Community");
|
|
59
|
-
logger_1.logger.info(message);
|
|
60
|
-
throw new AppError_1.AppError(message, 404);
|
|
61
|
-
}
|
|
62
|
-
const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
|
|
63
|
-
community_id: community.id,
|
|
64
|
-
member_id: user_id
|
|
65
|
-
});
|
|
66
|
-
if (!isCommunityMember) {
|
|
67
|
-
message = `You must be a member of ${community.name} to be able to make a comment on this post!`;
|
|
68
|
-
logger_1.logger.info(message);
|
|
69
|
-
throw new AppError_1.AppError(message, 403);
|
|
70
|
-
}
|
|
71
|
-
const createdPostComment = await this.postCommentRepository.create({
|
|
72
|
-
content,
|
|
73
|
-
post_id: post.id,
|
|
74
|
-
user_id
|
|
75
|
-
});
|
|
76
|
-
const comment = await this.postCommentRepository.findOneAndRelations({
|
|
77
|
-
where: { uuid: createdPostComment.uuid },
|
|
78
|
-
relations: ['user']
|
|
79
|
-
});
|
|
80
|
-
logger_1.logger.info("Post comment created successfully");
|
|
81
|
-
return {
|
|
82
|
-
successful: true,
|
|
83
|
-
data: comment ? PostCommentResource_1.PostCommentResource.toJSON(comment, user_id) : null,
|
|
84
|
-
message: "Post comment created successfully"
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async createReplyComment(postCommentData, user_id, comment_id) {
|
|
88
|
-
let message;
|
|
89
|
-
const { content, } = postCommentData;
|
|
90
|
-
const parentComment = await this.postCommentRepository.basicFindOneByConditions({
|
|
91
|
-
uuid: comment_id
|
|
92
|
-
});
|
|
93
|
-
if (!parentComment) {
|
|
94
|
-
message = "We couldn't find the comment you want to reply";
|
|
95
|
-
logger_1.logger.info(message);
|
|
96
|
-
throw new AppError_1.AppError(message, 404);
|
|
97
|
-
}
|
|
98
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
99
|
-
id: parentComment.post_id
|
|
100
|
-
});
|
|
101
|
-
if (!post) {
|
|
102
|
-
message = "We couldn't find the post that should have owned the comment you want to reply";
|
|
103
|
-
logger_1.logger.info(message);
|
|
104
|
-
throw new AppError_1.AppError(message, 404);
|
|
105
|
-
}
|
|
106
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
107
|
-
id: post.community_id
|
|
108
|
-
});
|
|
109
|
-
if (!community) {
|
|
110
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Community");
|
|
111
|
-
logger_1.logger.info(message);
|
|
112
|
-
throw new AppError_1.AppError(message, 404);
|
|
113
|
-
}
|
|
114
|
-
const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
|
|
115
|
-
community_id: community.id,
|
|
116
|
-
member_id: user_id
|
|
117
|
-
});
|
|
118
|
-
if (!isCommunityMember) {
|
|
119
|
-
message = `You must be a member of ${community.name} to be able to reply a comment on this post!`;
|
|
120
|
-
logger_1.logger.info(message);
|
|
121
|
-
throw new AppError_1.AppError(message, 403);
|
|
122
|
-
}
|
|
123
|
-
const createdPostComment = await this.postCommentRepository.create({
|
|
124
|
-
content,
|
|
125
|
-
post_id: post.id,
|
|
126
|
-
parent_id: parentComment.id,
|
|
127
|
-
user_id
|
|
128
|
-
});
|
|
129
|
-
const comment = await this.postCommentRepository.findOneAndRelations({
|
|
130
|
-
where: { uuid: createdPostComment.uuid },
|
|
131
|
-
relations: ['user']
|
|
132
|
-
});
|
|
133
|
-
logger_1.logger.info("Post's comment's reply created successfully");
|
|
134
|
-
return {
|
|
135
|
-
successful: true,
|
|
136
|
-
data: comment ? PostCommentResource_1.PostCommentResource.toJSON(comment, user_id) : null,
|
|
137
|
-
message: "Post' comment's reply created successfully"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async getComment(comment_id, user_id) {
|
|
141
|
-
let message;
|
|
142
|
-
const comment = await this.postCommentRepository.findOneAndRelations({
|
|
143
|
-
where: {
|
|
144
|
-
uuid: comment_id
|
|
145
|
-
},
|
|
146
|
-
relations: ['user']
|
|
147
|
-
});
|
|
148
|
-
if (!comment) {
|
|
149
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Comment");
|
|
150
|
-
logger_1.logger.info(message);
|
|
151
|
-
throw new AppError_1.AppError(message, 404);
|
|
152
|
-
}
|
|
153
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
154
|
-
id: comment.post_id
|
|
155
|
-
});
|
|
156
|
-
if (!post) {
|
|
157
|
-
message = "We couldn't find the post that should have owned this comment";
|
|
158
|
-
logger_1.logger.info(message);
|
|
159
|
-
throw new AppError_1.AppError(message, 404);
|
|
160
|
-
}
|
|
161
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
162
|
-
id: post.community_id
|
|
163
|
-
});
|
|
164
|
-
if (!community) {
|
|
165
|
-
message = "We couldn't find the community that owns the post on which this comment was made";
|
|
166
|
-
logger_1.logger.info(message);
|
|
167
|
-
throw new AppError_1.AppError(message, 404);
|
|
168
|
-
}
|
|
169
|
-
const qb = this.postCommentRepository
|
|
170
|
-
.getRepo()
|
|
171
|
-
.createQueryBuilder("comment")
|
|
172
|
-
.leftJoin("comment.user", "user")
|
|
173
|
-
.leftJoin("user.user_profile", "profile")
|
|
174
|
-
.leftJoin("profile.avatar", "avatar")
|
|
175
|
-
.where("comment.deleted_at IS NULL")
|
|
176
|
-
.andWhere("comment.post_id = :postId", { postId: post.id })
|
|
177
|
-
.andWhere("comment.uuid = :commentId", {
|
|
178
|
-
commentId: comment_id,
|
|
179
|
-
})
|
|
180
|
-
.take(1)
|
|
181
|
-
.orderBy("comment.created_at", "DESC");
|
|
182
|
-
/* ======================
|
|
183
|
-
SELECT FIELDS
|
|
184
|
-
====================== */
|
|
185
|
-
qb.select([
|
|
186
|
-
"comment.id",
|
|
187
|
-
"comment.uuid",
|
|
188
|
-
"comment.content",
|
|
189
|
-
"comment.created_at",
|
|
190
|
-
"comment.updated_at",
|
|
191
|
-
"user.id",
|
|
192
|
-
"user.uuid",
|
|
193
|
-
"user.full_name",
|
|
194
|
-
"avatar.url AS profile_image_url",
|
|
195
|
-
]);
|
|
196
|
-
/* ======================
|
|
197
|
-
REPLIES COUNT
|
|
198
|
-
====================== */
|
|
199
|
-
qb.addSelect(subQuery => {
|
|
200
|
-
return subQuery
|
|
201
|
-
.select("COUNT(r.id)")
|
|
202
|
-
.from(CommentModel_1.default, "r")
|
|
203
|
-
.where("r.parent_id = comment.id")
|
|
204
|
-
.andWhere("r.deleted_at IS NULL");
|
|
205
|
-
}, "replies_count");
|
|
206
|
-
// Check if user has liked the comment
|
|
207
|
-
qb.addSelect(`
|
|
208
|
-
EXISTS (
|
|
209
|
-
SELECT 1
|
|
210
|
-
FROM likes l
|
|
211
|
-
WHERE l.likeable_id = comment.id
|
|
212
|
-
AND l.likeable_type = :likeType
|
|
213
|
-
AND l.user_id = :user_id
|
|
214
|
-
AND l.deleted_at IS NULL
|
|
215
|
-
)
|
|
216
|
-
`, "has_liked")
|
|
217
|
-
.setParameter("likeType", IndexEnum_1.SYS_MODELS.POST_COMMENT_MODEL)
|
|
218
|
-
.setParameter("user_id", user_id);
|
|
219
|
-
/* ======================
|
|
220
|
-
LIKES COUNT (COMMENT)
|
|
221
|
-
====================== */
|
|
222
|
-
qb.addSelect(subQuery => {
|
|
223
|
-
return subQuery
|
|
224
|
-
.select("COUNT(l.id)")
|
|
225
|
-
.from(LikeModel_1.default, "l")
|
|
226
|
-
.where("l.likeable_id = comment.id")
|
|
227
|
-
.andWhere("l.likeable_type = :commentType")
|
|
228
|
-
.andWhere("l.deleted_at IS NULL");
|
|
229
|
-
}, "likes_count")
|
|
230
|
-
.setParameter("commentType", IndexEnum_1.SYS_MODELS.POST_COMMENT_MODEL);
|
|
231
|
-
const { entities, raw } = await qb.getRawAndEntities();
|
|
232
|
-
const foundComment = entities[0];
|
|
233
|
-
const { uuid, content, created_at, updated_at, user } = foundComment;
|
|
234
|
-
const data = {
|
|
235
|
-
uuid,
|
|
236
|
-
content,
|
|
237
|
-
created_at,
|
|
238
|
-
updated_at,
|
|
239
|
-
creator: {
|
|
240
|
-
uuid: user?.uuid,
|
|
241
|
-
full_name: user?.full_name,
|
|
242
|
-
profile_image_url: raw[0]?.profile_image_url,
|
|
243
|
-
},
|
|
244
|
-
replies_count: raw[0]?.replies_count,
|
|
245
|
-
likes_count: raw[0]?.likes_count,
|
|
246
|
-
has_liked: raw[0]?.has_liked,
|
|
247
|
-
};
|
|
248
|
-
return {
|
|
249
|
-
successful: true,
|
|
250
|
-
data,
|
|
251
|
-
message: "Comment fetched successfully!"
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async likeOrUnlikeComment(comment_id, user_id) {
|
|
255
|
-
let message;
|
|
256
|
-
const comment = await this.postCommentRepository.basicFindOneByConditions({
|
|
257
|
-
uuid: comment_id
|
|
258
|
-
});
|
|
259
|
-
if (!comment) {
|
|
260
|
-
message = "We couldn't find the comment you want to like/unlike";
|
|
261
|
-
logger_1.logger.info(message);
|
|
262
|
-
throw new AppError_1.AppError(message, 404);
|
|
263
|
-
}
|
|
264
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
265
|
-
id: comment.post_id
|
|
266
|
-
});
|
|
267
|
-
if (!post) {
|
|
268
|
-
message = "We couldn't find the post that should have owned the comment you want to like/unlike";
|
|
269
|
-
logger_1.logger.info(message);
|
|
270
|
-
throw new AppError_1.AppError(message, 404);
|
|
271
|
-
}
|
|
272
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
273
|
-
id: post.community_id
|
|
274
|
-
});
|
|
275
|
-
if (!community) {
|
|
276
|
-
message = "We couldn't find the community that owns the post that has the comment you want to like or unlike";
|
|
277
|
-
logger_1.logger.info(message);
|
|
278
|
-
throw new AppError_1.AppError(message, 404);
|
|
279
|
-
}
|
|
280
|
-
const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
|
|
281
|
-
community_id: community.id,
|
|
282
|
-
member_id: user_id
|
|
283
|
-
});
|
|
284
|
-
if (!isCommunityMember) {
|
|
285
|
-
message = `You must be a member of ${community.name} to be to like or unlike a post's comment in it!`;
|
|
286
|
-
logger_1.logger.info(message);
|
|
287
|
-
throw new AppError_1.AppError(message, 403);
|
|
288
|
-
}
|
|
289
|
-
const alreadyLikedComment = await this.likeRepository.basicFindOneByConditions({
|
|
290
|
-
likeable_id: comment.id,
|
|
291
|
-
likeable_type: IndexEnum_1.SYS_MODELS.POST_COMMENT_MODEL,
|
|
292
|
-
user_id
|
|
293
|
-
});
|
|
294
|
-
if (alreadyLikedComment) {
|
|
295
|
-
// Unlike the comment
|
|
296
|
-
await this.likeRepository.deleteByCondition({
|
|
297
|
-
user_id,
|
|
298
|
-
likeable_id: comment.id,
|
|
299
|
-
likeable_type: IndexEnum_1.SYS_MODELS.POST_COMMENT_MODEL
|
|
300
|
-
});
|
|
301
|
-
message = "Comment unliked successfully";
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
// Like the comment
|
|
305
|
-
await this.likeRepository.create({
|
|
306
|
-
user_id,
|
|
307
|
-
likeable_id: comment.id,
|
|
308
|
-
likeable_type: IndexEnum_1.SYS_MODELS.POST_COMMENT_MODEL
|
|
309
|
-
});
|
|
310
|
-
message = "Comment liked successfully";
|
|
311
|
-
}
|
|
312
|
-
return {
|
|
313
|
-
successful: true,
|
|
314
|
-
data: null,
|
|
315
|
-
message
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
async getPostComments(user_id, post_id, pageNumber) {
|
|
319
|
-
let message;
|
|
320
|
-
const page_number = pageNumber || 1;
|
|
321
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
322
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
323
|
-
uuid: post_id
|
|
324
|
-
});
|
|
325
|
-
if (!post) {
|
|
326
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Post");
|
|
327
|
-
logger_1.logger.info(message);
|
|
328
|
-
throw new AppError_1.AppError(message, 404);
|
|
329
|
-
}
|
|
330
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
331
|
-
id: post.community_id
|
|
332
|
-
});
|
|
333
|
-
if (!community) {
|
|
334
|
-
message = "We couldn't find the community that owns the post on which the comments were made";
|
|
335
|
-
logger_1.logger.info(message);
|
|
336
|
-
throw new AppError_1.AppError(message, 404);
|
|
337
|
-
}
|
|
338
|
-
const paginationDto = {
|
|
339
|
-
page_number, limit
|
|
340
|
-
};
|
|
341
|
-
const { data, total, perPage, page } = await this.postCommentRepository.getPagedPostComments(paginationDto, post.id, user_id);
|
|
342
|
-
const { entities, raw } = data;
|
|
343
|
-
const postCommentEntities = entities;
|
|
344
|
-
const rawPostComments = raw;
|
|
345
|
-
const postComments = postCommentEntities.map((entity, index) => {
|
|
346
|
-
const { uuid, content, created_at, updated_at, user } = entity;
|
|
347
|
-
return {
|
|
348
|
-
uuid,
|
|
349
|
-
content,
|
|
350
|
-
created_at,
|
|
351
|
-
updated_at,
|
|
352
|
-
creator: {
|
|
353
|
-
uuid: user?.uuid,
|
|
354
|
-
full_name: user?.full_name,
|
|
355
|
-
profile_image_url: rawPostComments[index]?.profile_image_url,
|
|
356
|
-
},
|
|
357
|
-
replies_count: rawPostComments[index]?.replies_count,
|
|
358
|
-
likes_count: rawPostComments[index]?.likes_count,
|
|
359
|
-
has_liked: rawPostComments[index]?.has_liked,
|
|
360
|
-
};
|
|
361
|
-
});
|
|
362
|
-
const pagedPostComments = (0, Paginator_1.paginator)({
|
|
363
|
-
total,
|
|
364
|
-
perPage,
|
|
365
|
-
currentPage: page_number,
|
|
366
|
-
data: postComments,
|
|
367
|
-
});
|
|
368
|
-
return {
|
|
369
|
-
successful: true,
|
|
370
|
-
data: pagedPostComments,
|
|
371
|
-
message: "Comments fetched successfully!"
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
async getCommentReplies(user_id, comment_id, pageNumber) {
|
|
375
|
-
let message;
|
|
376
|
-
const page_number = pageNumber || 1;
|
|
377
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
378
|
-
const parentComment = await this.postCommentRepository.basicFindOneByConditions({
|
|
379
|
-
uuid: comment_id
|
|
380
|
-
});
|
|
381
|
-
if (!parentComment) {
|
|
382
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Comment");
|
|
383
|
-
logger_1.logger.info(message);
|
|
384
|
-
throw new AppError_1.AppError(message, 404);
|
|
385
|
-
}
|
|
386
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
387
|
-
id: parentComment.post_id
|
|
388
|
-
});
|
|
389
|
-
if (!post) {
|
|
390
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Post");
|
|
391
|
-
logger_1.logger.info(message);
|
|
392
|
-
throw new AppError_1.AppError(message, 404);
|
|
393
|
-
}
|
|
394
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
395
|
-
id: post.community_id
|
|
396
|
-
});
|
|
397
|
-
if (!community) {
|
|
398
|
-
message = "We couldn't find the community that owns the post on which the comments were made";
|
|
399
|
-
logger_1.logger.info(message);
|
|
400
|
-
throw new AppError_1.AppError(message, 404);
|
|
401
|
-
}
|
|
402
|
-
const paginationDto = {
|
|
403
|
-
page_number,
|
|
404
|
-
limit
|
|
405
|
-
};
|
|
406
|
-
const { data, total, perPage, page } = await this.postCommentRepository.getPagedCommentReplies(paginationDto, parentComment.id, user_id);
|
|
407
|
-
const { entities, raw } = data;
|
|
408
|
-
const postCommentEntities = entities;
|
|
409
|
-
const rawPostComments = raw;
|
|
410
|
-
const postComments = postCommentEntities.map((entity, index) => {
|
|
411
|
-
const { uuid, content, created_at, updated_at, user } = entity;
|
|
412
|
-
return {
|
|
413
|
-
uuid,
|
|
414
|
-
content,
|
|
415
|
-
created_at,
|
|
416
|
-
updated_at,
|
|
417
|
-
creator: {
|
|
418
|
-
uuid: user?.uuid,
|
|
419
|
-
full_name: user?.full_name,
|
|
420
|
-
profile_image_url: rawPostComments[index]?.profile_image_url,
|
|
421
|
-
},
|
|
422
|
-
replies_count: rawPostComments[index]?.replies_count,
|
|
423
|
-
likes_count: rawPostComments[index]?.likes_count,
|
|
424
|
-
has_liked: rawPostComments[index]?.has_liked,
|
|
425
|
-
};
|
|
426
|
-
});
|
|
427
|
-
const pagedPostComments = (0, Paginator_1.paginator)({
|
|
428
|
-
total,
|
|
429
|
-
perPage,
|
|
430
|
-
currentPage: page_number,
|
|
431
|
-
data: postComments,
|
|
432
|
-
});
|
|
433
|
-
return {
|
|
434
|
-
successful: true,
|
|
435
|
-
data: pagedPostComments,
|
|
436
|
-
message: "Comments fetched successfully!"
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
async getCommentLikes(user_id, comment_id, pageNumber) {
|
|
440
|
-
let message;
|
|
441
|
-
const page_number = pageNumber || 1;
|
|
442
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
443
|
-
const comment = await this.postCommentRepository.basicFindOneByConditions({
|
|
444
|
-
uuid: comment_id
|
|
445
|
-
});
|
|
446
|
-
if (!comment) {
|
|
447
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Comment");
|
|
448
|
-
logger_1.logger.info(message);
|
|
449
|
-
throw new AppError_1.AppError(message, 404);
|
|
450
|
-
}
|
|
451
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
452
|
-
id: comment.post_id
|
|
453
|
-
});
|
|
454
|
-
if (!post) {
|
|
455
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Post");
|
|
456
|
-
logger_1.logger.info(message);
|
|
457
|
-
throw new AppError_1.AppError(message, 404);
|
|
458
|
-
}
|
|
459
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
460
|
-
id: post.community_id
|
|
461
|
-
});
|
|
462
|
-
if (!community) {
|
|
463
|
-
message = "We couldn't find the community that owns the post on which the comments were made";
|
|
464
|
-
logger_1.logger.info(message);
|
|
465
|
-
throw new AppError_1.AppError(message, 404);
|
|
466
|
-
}
|
|
467
|
-
const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
|
|
468
|
-
community_id: community.id,
|
|
469
|
-
member_id: user_id
|
|
470
|
-
});
|
|
471
|
-
if (!isCommunityMember) {
|
|
472
|
-
message = `You must be a member of ${community.name} to be able to read a comments in it!`;
|
|
473
|
-
logger_1.logger.info(message);
|
|
474
|
-
throw new AppError_1.AppError(message, 403);
|
|
475
|
-
}
|
|
476
|
-
const paginationDto = {
|
|
477
|
-
page_number,
|
|
478
|
-
metadata: {
|
|
479
|
-
comment_id: comment.id
|
|
480
|
-
},
|
|
481
|
-
limit
|
|
482
|
-
};
|
|
483
|
-
const { data, total, perPage, page } = await this.likeRepository.getPagedCommentUserLikes(paginationDto, user_id);
|
|
484
|
-
const { entities, raw } = data;
|
|
485
|
-
const commentUserLikes = raw.map((like) => {
|
|
486
|
-
return {
|
|
487
|
-
user: {
|
|
488
|
-
name: like?.user_full_name,
|
|
489
|
-
uuid: like?.user_uuid,
|
|
490
|
-
avatar_url: like?.avatar_url,
|
|
491
|
-
},
|
|
492
|
-
liked_at: like?.like_created_at
|
|
493
|
-
};
|
|
494
|
-
});
|
|
495
|
-
const pagedCommentLikes = (0, Paginator_1.paginator)({
|
|
496
|
-
total,
|
|
497
|
-
perPage,
|
|
498
|
-
currentPage: page_number,
|
|
499
|
-
data: commentUserLikes,
|
|
500
|
-
});
|
|
501
|
-
return {
|
|
502
|
-
successful: true,
|
|
503
|
-
data: pagedCommentLikes,
|
|
504
|
-
message: "Comment likes fetched successfully!"
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
async updateOneComment(postCommentData, comment_id, user_id) {
|
|
508
|
-
let message;
|
|
509
|
-
const { content } = postCommentData;
|
|
510
|
-
const comment = await this.postCommentRepository.findOneAndRelations({
|
|
511
|
-
where: {
|
|
512
|
-
uuid: comment_id,
|
|
513
|
-
user_id
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
if (!comment) {
|
|
517
|
-
message = "We couldn't find the comment you want to update";
|
|
518
|
-
logger_1.logger.info(message);
|
|
519
|
-
throw new AppError_1.AppError(message, 404);
|
|
520
|
-
}
|
|
521
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
522
|
-
id: comment.post_id
|
|
523
|
-
});
|
|
524
|
-
if (!post) {
|
|
525
|
-
message = "We couldn't find the post that should have owned the comment you want to update";
|
|
526
|
-
logger_1.logger.info(message);
|
|
527
|
-
throw new AppError_1.AppError(message, 404);
|
|
528
|
-
}
|
|
529
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
530
|
-
id: post.community_id
|
|
531
|
-
});
|
|
532
|
-
if (!community) {
|
|
533
|
-
message = "We couldn't find the community that owns the post on which this comment was made";
|
|
534
|
-
logger_1.logger.info(message);
|
|
535
|
-
throw new AppError_1.AppError(message, 404);
|
|
536
|
-
}
|
|
537
|
-
const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
|
|
538
|
-
community_id: community.id,
|
|
539
|
-
member_id: user_id
|
|
540
|
-
});
|
|
541
|
-
if (!isCommunityMember) {
|
|
542
|
-
message = `You must be a member of ${community.name} to be able to update a comment on this post!`;
|
|
543
|
-
logger_1.logger.info(message);
|
|
544
|
-
throw new AppError_1.AppError(message, 403);
|
|
545
|
-
}
|
|
546
|
-
const updatedComment = await this.postCommentRepository.updateOne({
|
|
547
|
-
uuid: comment.uuid,
|
|
548
|
-
user_id,
|
|
549
|
-
}, {
|
|
550
|
-
content
|
|
551
|
-
});
|
|
552
|
-
return {
|
|
553
|
-
successful: true,
|
|
554
|
-
data: updatedComment,
|
|
555
|
-
message: "Comment updated successfully!"
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
async deleteOneComment(comment_id, user_id) {
|
|
559
|
-
let message;
|
|
560
|
-
const comment = await this.postCommentRepository.findOneAndRelations({
|
|
561
|
-
where: {
|
|
562
|
-
uuid: comment_id,
|
|
563
|
-
user_id
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
if (!comment) {
|
|
567
|
-
message = "We couldn't find the comment you want to delete";
|
|
568
|
-
logger_1.logger.info(message);
|
|
569
|
-
throw new AppError_1.AppError(message, 404);
|
|
570
|
-
}
|
|
571
|
-
const post = await this.postRepository.basicFindOneByConditions({
|
|
572
|
-
id: comment.post_id
|
|
573
|
-
});
|
|
574
|
-
if (!post) {
|
|
575
|
-
message = "We couldn't find the post that should have owned the comment you want to delete";
|
|
576
|
-
logger_1.logger.info(message);
|
|
577
|
-
throw new AppError_1.AppError(message, 404);
|
|
578
|
-
}
|
|
579
|
-
const community = await this.communityRepository.basicFindOneByConditions({
|
|
580
|
-
id: post.community_id
|
|
581
|
-
});
|
|
582
|
-
if (!community) {
|
|
583
|
-
message = "We couldn't find the community that owns the post on which this comment was made";
|
|
584
|
-
logger_1.logger.info(message);
|
|
585
|
-
throw new AppError_1.AppError(message, 404);
|
|
586
|
-
}
|
|
587
|
-
const isCommunityMember = await this.communityMemberRepository.basicFindOneByConditions({
|
|
588
|
-
community_id: community.id,
|
|
589
|
-
member_id: user_id
|
|
590
|
-
});
|
|
591
|
-
if (!isCommunityMember) {
|
|
592
|
-
message = `You must be a member of ${community.name} to be able to delete a comment on this post!`;
|
|
593
|
-
logger_1.logger.info(message);
|
|
594
|
-
throw new AppError_1.AppError(message, 403);
|
|
595
|
-
}
|
|
596
|
-
await this.postCommentRepository.deleteByCondition({
|
|
597
|
-
uuid: comment.uuid,
|
|
598
|
-
user_id,
|
|
599
|
-
});
|
|
600
|
-
return {
|
|
601
|
-
successful: true,
|
|
602
|
-
data: null,
|
|
603
|
-
message: "Comment deleted successfully!"
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
PostCommentService = __decorate([
|
|
608
|
-
(0, typedi_1.Service)(),
|
|
609
|
-
__metadata("design:paramtypes", [])
|
|
610
|
-
], PostCommentService);
|
|
611
|
-
exports.default = PostCommentService;
|