@aurispec/core-backend 1.0.4 → 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.
- 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/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/ReviewModel.d.ts +5 -0
- package/dist/models/ReviewModel.d.ts.map +1 -1
- package/dist/models/ReviewModel.js +19 -0
- 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,308 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const typedi_1 = require("typedi");
|
|
13
|
-
const AppError_1 = require("../../common/errors/AppError");
|
|
14
|
-
const UserRepository_1 = require("../../repositories/UserRepository");
|
|
15
|
-
const DiagnosisLevelRepository_1 = require("@/repositories/DiagnosisLevelRepository");
|
|
16
|
-
const InterestRepository_1 = require("@/repositories/InterestRepository");
|
|
17
|
-
const UserEnums_1 = require("@/common/enums/UserEnums");
|
|
18
|
-
const SpeechRepository_1 = require("@/repositories/SpeechRepository");
|
|
19
|
-
const EducationRepository_1 = require("@/repositories/EducationRepository");
|
|
20
|
-
const ChallengeRepository_1 = require("@/repositories/ChallengeRepository");
|
|
21
|
-
const typeorm_1 = require("typeorm");
|
|
22
|
-
const GoalRepository_1 = require("@/repositories/GoalRepository");
|
|
23
|
-
let CompleteProfileService = class CompleteProfileService {
|
|
24
|
-
userRepository;
|
|
25
|
-
diagnosisLevelRepository;
|
|
26
|
-
interestRepository;
|
|
27
|
-
userProfileRepository;
|
|
28
|
-
speechRepository;
|
|
29
|
-
educationRepository;
|
|
30
|
-
challengeRepository;
|
|
31
|
-
goalRepository;
|
|
32
|
-
constructor() {
|
|
33
|
-
this.userRepository = new UserRepository_1.UserRepository();
|
|
34
|
-
this.diagnosisLevelRepository = new DiagnosisLevelRepository_1.DiagnosisLevelRepository();
|
|
35
|
-
this.interestRepository = new InterestRepository_1.InterestRepository();
|
|
36
|
-
this.userProfileRepository = new UserRepository_1.UserProfileRepository();
|
|
37
|
-
this.speechRepository = new SpeechRepository_1.SpeechRepository();
|
|
38
|
-
this.educationRepository = new EducationRepository_1.EducationRepository();
|
|
39
|
-
this.challengeRepository = new ChallengeRepository_1.ChallengeRepository();
|
|
40
|
-
this.goalRepository = new GoalRepository_1.GoalRepository();
|
|
41
|
-
}
|
|
42
|
-
async submitStepOneForm(createStepOneFormDto, user_id) {
|
|
43
|
-
let message;
|
|
44
|
-
const { interest, diagnosis_level, date_of_birth, user_relationship } = createStepOneFormDto;
|
|
45
|
-
const foundDiagnosis_level = await this.diagnosisLevelRepository.basicFindOneByConditions({ uuid: diagnosis_level });
|
|
46
|
-
if (!foundDiagnosis_level)
|
|
47
|
-
throw new AppError_1.AppError('Selected diagnosis level is invalid', 404);
|
|
48
|
-
const foundInterest = await this.interestRepository.basicFindOneByConditions({ uuid: interest });
|
|
49
|
-
if (!foundInterest)
|
|
50
|
-
throw new AppError_1.AppError('Selected interest is invalid', 404);
|
|
51
|
-
let existingProfile = await this.userProfileRepository.getRepo().findOne({ where: { user: { id: user_id } } });
|
|
52
|
-
if (existingProfile) {
|
|
53
|
-
await this.userProfileRepository.updateOne({
|
|
54
|
-
user_id,
|
|
55
|
-
}, {
|
|
56
|
-
diagnosis_level_id: foundDiagnosis_level.id,
|
|
57
|
-
interest_id: foundInterest.id,
|
|
58
|
-
account_type: user_relationship,
|
|
59
|
-
date_of_birth: date_of_birth,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
await this.userProfileRepository.create({
|
|
64
|
-
diagnosis_level_id: foundDiagnosis_level.id,
|
|
65
|
-
interest_id: foundInterest.id,
|
|
66
|
-
user_id,
|
|
67
|
-
account_type: user_relationship,
|
|
68
|
-
date_of_birth: date_of_birth,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
await this.userRepository.updateOne({
|
|
72
|
-
id: user_id
|
|
73
|
-
}, {
|
|
74
|
-
profile_level: UserEnums_1.ProfileLevel.STEP_ONE
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
successful: true,
|
|
78
|
-
data: null,
|
|
79
|
-
message: "Step 1 form submitted successfully"
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
async getStepOneFormOptions() {
|
|
83
|
-
const foundDiagnosis_level = await this.diagnosisLevelRepository.getRepo().find({
|
|
84
|
-
select: ['name', 'uuid']
|
|
85
|
-
});
|
|
86
|
-
const foundInterest = await this.interestRepository.getRepo().find({
|
|
87
|
-
select: ['name', 'uuid']
|
|
88
|
-
});
|
|
89
|
-
return {
|
|
90
|
-
successful: true,
|
|
91
|
-
data: {
|
|
92
|
-
interests: foundInterest,
|
|
93
|
-
diagnosis_levels: foundDiagnosis_level,
|
|
94
|
-
user_relationship: UserEnums_1.AccountType
|
|
95
|
-
},
|
|
96
|
-
message: "Step 1 form data fetched successfully!"
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
async submitStepTwoForm(createSteptwoFormDto, user_id) {
|
|
100
|
-
let message;
|
|
101
|
-
const { gender, speech } = createSteptwoFormDto;
|
|
102
|
-
const foundSpeech = await this.speechRepository.basicFindOneByConditions({ uuid: speech });
|
|
103
|
-
if (!foundSpeech)
|
|
104
|
-
throw new AppError_1.AppError('Selected speech is invalid', 404);
|
|
105
|
-
let existingProfile = await this.userProfileRepository.getRepo().findOne({ where: { user: { id: user_id } } });
|
|
106
|
-
if (existingProfile) {
|
|
107
|
-
await this.userProfileRepository.updateOne({
|
|
108
|
-
user_id,
|
|
109
|
-
}, {
|
|
110
|
-
gender,
|
|
111
|
-
speech_id: foundSpeech.id,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
await this.userProfileRepository.create({
|
|
116
|
-
gender,
|
|
117
|
-
speech_id: foundSpeech.id,
|
|
118
|
-
user_id,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
await this.userRepository.updateOne({
|
|
122
|
-
id: user_id
|
|
123
|
-
}, {
|
|
124
|
-
profile_level: UserEnums_1.ProfileLevel.STEP_TWO
|
|
125
|
-
});
|
|
126
|
-
return {
|
|
127
|
-
successful: true,
|
|
128
|
-
data: null,
|
|
129
|
-
message: "Step 2 form submitted successfully"
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
async getStepTwoFormOptions() {
|
|
133
|
-
const speeches = await this.speechRepository.getRepo().find({
|
|
134
|
-
select: ['name', 'uuid']
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
successful: true,
|
|
138
|
-
data: {
|
|
139
|
-
gender: UserEnums_1.GENDER,
|
|
140
|
-
speeches
|
|
141
|
-
},
|
|
142
|
-
message: "Step 2 form data fetched successfully!"
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
async submitStepThreeForm(createStepthreeFormDto, user_id) {
|
|
146
|
-
let message;
|
|
147
|
-
const { education, challenges_selections, other_challenges } = createStepthreeFormDto;
|
|
148
|
-
const foundEducation = await this.educationRepository.basicFindOneByConditions({ uuid: education });
|
|
149
|
-
if (!foundEducation)
|
|
150
|
-
throw new AppError_1.AppError('Selected education is invalid', 404);
|
|
151
|
-
let challengesId = [];
|
|
152
|
-
challenges_selections.map(async (challenge) => {
|
|
153
|
-
const existingChallenge = await this.challengeRepository.basicFindOneByConditions({ name: challenge });
|
|
154
|
-
if (!existingChallenge) {
|
|
155
|
-
const foundChallenge = await this.challengeRepository.basicFindOneByConditions({ uuid: challenge });
|
|
156
|
-
if (!foundChallenge)
|
|
157
|
-
throw new AppError_1.AppError('Selected challenge is invalid', 404);
|
|
158
|
-
challengesId.push(foundChallenge.id);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
if (other_challenges && other_challenges.length > 0) {
|
|
162
|
-
other_challenges.map(async (challenge) => {
|
|
163
|
-
const foundChallenge = await this.challengeRepository.create({
|
|
164
|
-
name: challenge,
|
|
165
|
-
user_id
|
|
166
|
-
});
|
|
167
|
-
challengesId.push(foundChallenge.id);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
let existingProfile = await this.userProfileRepository.getRepo().findOne({ where: { user: { id: user_id } } });
|
|
171
|
-
if (existingProfile) {
|
|
172
|
-
await this.userProfileRepository.updateOne({
|
|
173
|
-
user_id,
|
|
174
|
-
}, {
|
|
175
|
-
child_education_id: foundEducation.id,
|
|
176
|
-
challenges: challengesId,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
await this.userProfileRepository.create({
|
|
181
|
-
child_education_id: foundEducation.id,
|
|
182
|
-
challenges: challengesId,
|
|
183
|
-
user_id,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
await this.userRepository.updateOne({
|
|
187
|
-
id: user_id
|
|
188
|
-
}, {
|
|
189
|
-
profile_level: UserEnums_1.ProfileLevel.STEP_THREE
|
|
190
|
-
});
|
|
191
|
-
return {
|
|
192
|
-
successful: true,
|
|
193
|
-
data: null,
|
|
194
|
-
message: "Step 3 form submitted successfully"
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
async getStepThreeFormOptions() {
|
|
198
|
-
const challenges = await this.challengeRepository.getRepo().find({
|
|
199
|
-
select: ['name', 'uuid'],
|
|
200
|
-
where: {
|
|
201
|
-
user_id: (0, typeorm_1.IsNull)()
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
const education = await this.educationRepository.getRepo().find({
|
|
205
|
-
select: ['name', 'uuid'],
|
|
206
|
-
});
|
|
207
|
-
return {
|
|
208
|
-
successful: true,
|
|
209
|
-
data: {
|
|
210
|
-
education,
|
|
211
|
-
challenges
|
|
212
|
-
},
|
|
213
|
-
message: "Step 3 form data fetched successfully!"
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
async submitStepFiveForm(createStepFiveFormDto, user_id) {
|
|
217
|
-
let message;
|
|
218
|
-
const { city, state, country, coordinates } = createStepFiveFormDto;
|
|
219
|
-
let existingProfile = await this.userProfileRepository.getRepo().findOne({ where: { user: { id: user_id } } });
|
|
220
|
-
if (existingProfile) {
|
|
221
|
-
await this.userProfileRepository.updateWithCoordinates({
|
|
222
|
-
user_id,
|
|
223
|
-
}, {
|
|
224
|
-
location: {
|
|
225
|
-
city,
|
|
226
|
-
state,
|
|
227
|
-
country,
|
|
228
|
-
coordinates
|
|
229
|
-
}
|
|
230
|
-
}, coordinates.long, coordinates.lat);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
await this.userProfileRepository.createWithCoordinates({
|
|
234
|
-
location: {
|
|
235
|
-
city,
|
|
236
|
-
state,
|
|
237
|
-
country,
|
|
238
|
-
coordinates
|
|
239
|
-
}
|
|
240
|
-
}, coordinates.long, coordinates.lat);
|
|
241
|
-
}
|
|
242
|
-
await this.userRepository.updateOne({
|
|
243
|
-
id: user_id
|
|
244
|
-
}, {
|
|
245
|
-
profile_level: UserEnums_1.ProfileLevel.COMPLETED
|
|
246
|
-
});
|
|
247
|
-
return {
|
|
248
|
-
successful: true,
|
|
249
|
-
data: null,
|
|
250
|
-
message: "Step 4 form submitted successfully"
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
async submitStepFourForm(createStepFourFormDto, user_id) {
|
|
254
|
-
let message;
|
|
255
|
-
const { goals } = createStepFourFormDto;
|
|
256
|
-
let goalsId = [];
|
|
257
|
-
goals.map(async (goal) => {
|
|
258
|
-
const existingGoal = await this.goalRepository.basicFindOneByConditions({ name: goal });
|
|
259
|
-
if (!existingGoal) {
|
|
260
|
-
const foundGoal = await this.goalRepository.basicFindOneByConditions({ uuid: goal });
|
|
261
|
-
if (!foundGoal)
|
|
262
|
-
throw new AppError_1.AppError('Selected goal is invalid', 404);
|
|
263
|
-
goalsId.push(foundGoal.id);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
let existingProfile = await this.userProfileRepository.getRepo().findOne({ where: { user: { id: user_id } } });
|
|
267
|
-
if (existingProfile) {
|
|
268
|
-
await this.userProfileRepository.updateOne({
|
|
269
|
-
user_id,
|
|
270
|
-
}, {
|
|
271
|
-
goals: goalsId,
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
await this.userProfileRepository.create({
|
|
276
|
-
goals: goalsId,
|
|
277
|
-
user_id,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
await this.userRepository.updateOne({
|
|
281
|
-
id: user_id
|
|
282
|
-
}, {
|
|
283
|
-
profile_level: UserEnums_1.ProfileLevel.STEP_FOUR
|
|
284
|
-
});
|
|
285
|
-
return {
|
|
286
|
-
successful: true,
|
|
287
|
-
data: null,
|
|
288
|
-
message: "Step 5 form submitted successfully"
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
async getStepFourFormOptions() {
|
|
292
|
-
const goals = await this.goalRepository.getRepo().find({
|
|
293
|
-
select: ['name', 'uuid'],
|
|
294
|
-
});
|
|
295
|
-
return {
|
|
296
|
-
successful: true,
|
|
297
|
-
data: {
|
|
298
|
-
goals
|
|
299
|
-
},
|
|
300
|
-
message: "Step 5 form data fetched successfully!"
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
CompleteProfileService = __decorate([
|
|
305
|
-
(0, typedi_1.Service)(),
|
|
306
|
-
__metadata("design:paramtypes", [])
|
|
307
|
-
], CompleteProfileService);
|
|
308
|
-
exports.default = CompleteProfileService;
|
|
@@ -1,338 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const typedi_1 = require("typedi");
|
|
13
|
-
const logger_1 = require("../../common/configs/logger");
|
|
14
|
-
const AppError_1 = require("../../common/errors/AppError");
|
|
15
|
-
const messages_1 = require("../../common/constants/messages");
|
|
16
|
-
const ConnectionRepository_1 = require("@/repositories/ConnectionRepository");
|
|
17
|
-
const Paginator_1 = require("@/transformers/Paginator");
|
|
18
|
-
const ConnectionEnum_1 = require("@/common/enums/ConnectionEnum");
|
|
19
|
-
const UserRepository_1 = require("@/repositories/UserRepository");
|
|
20
|
-
const configs_1 = require("@/common/configs");
|
|
21
|
-
const NotificationRepository_1 = require("@/repositories/NotificationRepository");
|
|
22
|
-
const NotificationEnum_1 = require("@/common/enums/NotificationEnum");
|
|
23
|
-
const IndexEnum_1 = require("@/common/enums/IndexEnum");
|
|
24
|
-
const typeorm_1 = require("typeorm");
|
|
25
|
-
const UserResource_1 = require("@/transformers/resources/UserResource");
|
|
26
|
-
let ConnectionService = class ConnectionService {
|
|
27
|
-
connectionRepository;
|
|
28
|
-
userRepository;
|
|
29
|
-
notificationRepository;
|
|
30
|
-
constructor() {
|
|
31
|
-
this.notificationRepository = new NotificationRepository_1.NotificationRepository();
|
|
32
|
-
this.userRepository = new UserRepository_1.UserRepository();
|
|
33
|
-
this.connectionRepository = new ConnectionRepository_1.ConnectionRepository();
|
|
34
|
-
}
|
|
35
|
-
async sendConnectionRequest(receiver_id, user_id) {
|
|
36
|
-
let message;
|
|
37
|
-
const connectionReceiver = await this.userRepository.findOneAndRelations({
|
|
38
|
-
where: {
|
|
39
|
-
uuid: receiver_id,
|
|
40
|
-
id: (0, typeorm_1.Not)(user_id)
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
if (!connectionReceiver) {
|
|
44
|
-
message = messages_1.dynamic_messages.NOT_FOUND("User account");
|
|
45
|
-
logger_1.logger.info(message);
|
|
46
|
-
throw new AppError_1.AppError(message, 404);
|
|
47
|
-
}
|
|
48
|
-
const connectionSender = await this.userRepository.basicFindOneByConditions({
|
|
49
|
-
id: user_id
|
|
50
|
-
});
|
|
51
|
-
if (!connectionSender) {
|
|
52
|
-
message = messages_1.dynamic_messages.NOT_FOUND("User account");
|
|
53
|
-
logger_1.logger.info(message);
|
|
54
|
-
throw new AppError_1.AppError(message, 404);
|
|
55
|
-
}
|
|
56
|
-
const connection = await this.connectionRepository.findOneAndRelations({
|
|
57
|
-
where: [
|
|
58
|
-
{
|
|
59
|
-
sender_id: connectionReceiver.id
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
receiver_id: connectionReceiver.id
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
relations: ['receiver', 'sender']
|
|
66
|
-
});
|
|
67
|
-
if (connection && connection?.status === ConnectionEnum_1.ConnectionStatus.ACCEPTED) {
|
|
68
|
-
message = `${connectionReceiver?.full_name} is already a connection`;
|
|
69
|
-
logger_1.logger.info(message);
|
|
70
|
-
throw new AppError_1.AppError(message, 400);
|
|
71
|
-
}
|
|
72
|
-
if (connection && connection?.status === ConnectionEnum_1.ConnectionStatus.PENDING) {
|
|
73
|
-
message = `Your connection request is still pending`;
|
|
74
|
-
logger_1.logger.info(message);
|
|
75
|
-
throw new AppError_1.AppError(message, 400);
|
|
76
|
-
}
|
|
77
|
-
const newConnection = await this.connectionRepository.create({
|
|
78
|
-
sender_id: user_id,
|
|
79
|
-
receiver_id: connectionReceiver.id
|
|
80
|
-
});
|
|
81
|
-
await this.notificationRepository.save({
|
|
82
|
-
user_id: connectionReceiver.id,
|
|
83
|
-
type: NotificationEnum_1.NotificationType.NEW_CONNECTION_REQUEST,
|
|
84
|
-
message: `You have a new connection request from ${connectionSender.full_name}`,
|
|
85
|
-
notifiable_id: newConnection.id,
|
|
86
|
-
notifiable_type: IndexEnum_1.SYS_MODELS.CONNECTION_MODEL
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
successful: true,
|
|
90
|
-
data: null,
|
|
91
|
-
message: `Your connection request was successfully sent!`
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async rejectConnectionRequest(connection_id, user_id, rejection_type) {
|
|
95
|
-
switch (rejection_type) {
|
|
96
|
-
case ConnectionEnum_1.ConnectionRejectionType.REJECT_CONNECTION:
|
|
97
|
-
return await this.rejectReceivedConnectionRequest(user_id, connection_id);
|
|
98
|
-
case ConnectionEnum_1.ConnectionRejectionType.WITHDRAW_CONNECTION:
|
|
99
|
-
return await this.withdrawConnectionRequest(user_id, connection_id);
|
|
100
|
-
case ConnectionEnum_1.ConnectionRejectionType.REJECT_CONNECTION:
|
|
101
|
-
return await this.cancelConnection(user_id, connection_id);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async rejectReceivedConnectionRequest(user_id, connection_id) {
|
|
105
|
-
let message;
|
|
106
|
-
const connection = await this.connectionRepository.findOneAndRelations({
|
|
107
|
-
where: {
|
|
108
|
-
receiver_id: user_id,
|
|
109
|
-
uuid: connection_id
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
if (!connection) {
|
|
113
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Connection");
|
|
114
|
-
logger_1.logger.info(message);
|
|
115
|
-
throw new AppError_1.AppError(message, 404);
|
|
116
|
-
}
|
|
117
|
-
if (connection && connection?.status === ConnectionEnum_1.ConnectionStatus.ACCEPTED) {
|
|
118
|
-
message = `${connection?.sender?.full_name}' connection request has already been accepted`;
|
|
119
|
-
logger_1.logger.info(message);
|
|
120
|
-
throw new AppError_1.AppError(message, 400);
|
|
121
|
-
}
|
|
122
|
-
await this.connectionRepository.deleteByCondition({
|
|
123
|
-
receiver_id: user_id,
|
|
124
|
-
uuid: connection_id
|
|
125
|
-
});
|
|
126
|
-
return {
|
|
127
|
-
successful: true,
|
|
128
|
-
data: null,
|
|
129
|
-
message: `Connection request was declined successfully`
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
async withdrawConnectionRequest(user_id, connection_id) {
|
|
133
|
-
let message;
|
|
134
|
-
const connection = await this.connectionRepository.findOneAndRelations({
|
|
135
|
-
where: {
|
|
136
|
-
sender_id: user_id,
|
|
137
|
-
uuid: connection_id
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
if (!connection) {
|
|
141
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Connection");
|
|
142
|
-
logger_1.logger.info(message);
|
|
143
|
-
throw new AppError_1.AppError(message, 404);
|
|
144
|
-
}
|
|
145
|
-
if (connection && connection?.status === ConnectionEnum_1.ConnectionStatus.ACCEPTED) {
|
|
146
|
-
message = `${connection?.sender?.full_name}' connection request has already been accepted`;
|
|
147
|
-
logger_1.logger.info(message);
|
|
148
|
-
throw new AppError_1.AppError(message, 400);
|
|
149
|
-
}
|
|
150
|
-
await this.connectionRepository.deleteByCondition({
|
|
151
|
-
sender_id: user_id,
|
|
152
|
-
uuid: connection_id
|
|
153
|
-
});
|
|
154
|
-
return {
|
|
155
|
-
successful: true,
|
|
156
|
-
data: null,
|
|
157
|
-
message: `Connection request was declined successfully`
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
async cancelConnection(user_id, connection_id) {
|
|
161
|
-
let message;
|
|
162
|
-
const connection = await this.connectionRepository.findOneAndRelations({
|
|
163
|
-
where: [
|
|
164
|
-
{
|
|
165
|
-
sender_id: user_id,
|
|
166
|
-
uuid: connection_id,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
receiver_id: user_id,
|
|
170
|
-
uuid: connection_id
|
|
171
|
-
}
|
|
172
|
-
]
|
|
173
|
-
});
|
|
174
|
-
if (!connection) {
|
|
175
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Connection");
|
|
176
|
-
logger_1.logger.info(message);
|
|
177
|
-
throw new AppError_1.AppError(message, 404);
|
|
178
|
-
}
|
|
179
|
-
if (connection && connection?.status !== ConnectionEnum_1.ConnectionStatus.ACCEPTED) {
|
|
180
|
-
message = `You can only cancel an accepted connection!`;
|
|
181
|
-
logger_1.logger.info(message);
|
|
182
|
-
throw new AppError_1.AppError(message, 400);
|
|
183
|
-
}
|
|
184
|
-
await this.connectionRepository.deleteByCondition({
|
|
185
|
-
uuid: connection_id
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
188
|
-
successful: true,
|
|
189
|
-
data: null,
|
|
190
|
-
message: `Connection was cancelled successfully`
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
async acceptConnection(connection_id, user_id) {
|
|
194
|
-
let message;
|
|
195
|
-
const user = await this.userRepository.basicFindOneByConditions({
|
|
196
|
-
id: user_id
|
|
197
|
-
});
|
|
198
|
-
const connection = await this.connectionRepository.findOneAndRelations({
|
|
199
|
-
where: {
|
|
200
|
-
receiver_id: user_id,
|
|
201
|
-
uuid: connection_id
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
if (!connection) {
|
|
205
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Connection");
|
|
206
|
-
logger_1.logger.info(message);
|
|
207
|
-
throw new AppError_1.AppError(message, 404);
|
|
208
|
-
}
|
|
209
|
-
if (!user) {
|
|
210
|
-
message = messages_1.dynamic_messages.NOT_FOUND("User account");
|
|
211
|
-
logger_1.logger.info(message);
|
|
212
|
-
throw new AppError_1.AppError(message, 404);
|
|
213
|
-
}
|
|
214
|
-
if (connection && connection?.status !== ConnectionEnum_1.ConnectionStatus.ACCEPTED) {
|
|
215
|
-
message = `You have already accepted this connection!`;
|
|
216
|
-
logger_1.logger.info(message);
|
|
217
|
-
throw new AppError_1.AppError(message, 400);
|
|
218
|
-
}
|
|
219
|
-
await this.connectionRepository.updateOne({
|
|
220
|
-
uuid: connection_id,
|
|
221
|
-
receiver_id: user_id
|
|
222
|
-
}, {
|
|
223
|
-
status: ConnectionEnum_1.ConnectionStatus.ACCEPTED
|
|
224
|
-
});
|
|
225
|
-
await this.notificationRepository.save({
|
|
226
|
-
user_id: connection?.sender_id,
|
|
227
|
-
type: NotificationEnum_1.NotificationType.NEW_CONNECTION_REQUEST,
|
|
228
|
-
message: `${user.full_name} accepted your have a new connection request`,
|
|
229
|
-
notifiable_id: connection.id,
|
|
230
|
-
notifiable_type: IndexEnum_1.SYS_MODELS.CONNECTION_MODEL
|
|
231
|
-
});
|
|
232
|
-
return {
|
|
233
|
-
successful: true,
|
|
234
|
-
data: null,
|
|
235
|
-
message: `Connection was accepted] successfully`
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
async fetchAcceptedConnection(user_id, pageNumber) {
|
|
239
|
-
const page_number = pageNumber || 1;
|
|
240
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
241
|
-
const options = {
|
|
242
|
-
metadata: {
|
|
243
|
-
user_id
|
|
244
|
-
},
|
|
245
|
-
page_number,
|
|
246
|
-
limit
|
|
247
|
-
};
|
|
248
|
-
const { rows, total } = await this.connectionRepository.getAcceptedConnections(options);
|
|
249
|
-
const connections = rows.map((connection, index) => ({
|
|
250
|
-
uuid: connection.uuid,
|
|
251
|
-
created_at: connection.created_at,
|
|
252
|
-
status: connection.status,
|
|
253
|
-
sender: {
|
|
254
|
-
...UserResource_1.UserResource.userToJSON(connection.sender)
|
|
255
|
-
},
|
|
256
|
-
receiver: {
|
|
257
|
-
...UserResource_1.UserResource.userToJSON(connection.receiver)
|
|
258
|
-
}
|
|
259
|
-
}));
|
|
260
|
-
const data = (0, Paginator_1.paginator)({
|
|
261
|
-
total,
|
|
262
|
-
perPage: limit,
|
|
263
|
-
currentPage: page_number,
|
|
264
|
-
data: connections,
|
|
265
|
-
});
|
|
266
|
-
return {
|
|
267
|
-
successful: true,
|
|
268
|
-
data,
|
|
269
|
-
message: `Connections fetched successfully`
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
async getReceivedPendingConnectionRequests(user_id, pageNumber) {
|
|
273
|
-
const page_number = pageNumber || 1;
|
|
274
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
275
|
-
const options = {
|
|
276
|
-
metadata: {
|
|
277
|
-
user_id
|
|
278
|
-
},
|
|
279
|
-
page_number,
|
|
280
|
-
limit
|
|
281
|
-
};
|
|
282
|
-
const { rows, total } = await this.connectionRepository.getReceivedPendingConnectionRequests(options);
|
|
283
|
-
const connections = rows.map((connection, index) => ({
|
|
284
|
-
uuid: connection.uuid,
|
|
285
|
-
created_at: connection.created_at,
|
|
286
|
-
status: connection.status,
|
|
287
|
-
sender: {
|
|
288
|
-
...UserResource_1.UserResource.userToJSON(connection.sender)
|
|
289
|
-
}
|
|
290
|
-
}));
|
|
291
|
-
const data = (0, Paginator_1.paginator)({
|
|
292
|
-
total,
|
|
293
|
-
perPage: limit,
|
|
294
|
-
currentPage: page_number,
|
|
295
|
-
data: connections,
|
|
296
|
-
});
|
|
297
|
-
return {
|
|
298
|
-
successful: true,
|
|
299
|
-
data,
|
|
300
|
-
message: `Connections requests fetched successfully`
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
async getRecommendedConnctions(user_id, pageNumber) {
|
|
304
|
-
let message;
|
|
305
|
-
const page_number = pageNumber || 1;
|
|
306
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
307
|
-
const dataFetchParams = {
|
|
308
|
-
page_number,
|
|
309
|
-
limit,
|
|
310
|
-
metadata: {
|
|
311
|
-
user_id
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
const { data, total, perPage, page } = await this.connectionRepository.getRecommendedConnctions(dataFetchParams);
|
|
315
|
-
const { raw, entities } = data;
|
|
316
|
-
const users = entities.map((user, index) => ({
|
|
317
|
-
...UserResource_1.UserResource.userToJSON(user),
|
|
318
|
-
connection_state: raw[index].connection_state,
|
|
319
|
-
}));
|
|
320
|
-
const connections = (0, Paginator_1.paginator)({
|
|
321
|
-
total,
|
|
322
|
-
perPage,
|
|
323
|
-
currentPage: page,
|
|
324
|
-
data: users,
|
|
325
|
-
});
|
|
326
|
-
message = messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("User");
|
|
327
|
-
return {
|
|
328
|
-
successful: true,
|
|
329
|
-
data: connections,
|
|
330
|
-
message
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
ConnectionService = __decorate([
|
|
335
|
-
(0, typedi_1.Service)(),
|
|
336
|
-
__metadata("design:paramtypes", [])
|
|
337
|
-
], ConnectionService);
|
|
338
|
-
exports.default = ConnectionService;
|