@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.
- package/dist/common/configs/cloudinary.d.ts +1 -1
- package/dist/common/configs/cloudinary.d.ts.map +1 -1
- package/dist/common/configs/cloudinary.js +2 -1
- package/dist/common/utils/index.d.ts +5 -0
- package/dist/common/utils/index.d.ts.map +1 -1
- package/dist/common/utils/index.js +16 -0
- 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,362 +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 UserRepository_1 = require("../../repositories/UserRepository");
|
|
16
|
-
const configs_1 = require("../../common/configs");
|
|
17
|
-
const utils_1 = require("../../common/utils");
|
|
18
|
-
const UserEnums_1 = require("../../common/enums/UserEnums");
|
|
19
|
-
// import UserModel from "../models/UserModel";
|
|
20
|
-
const messages_1 = require("../../common/constants/messages");
|
|
21
|
-
const UserResource_1 = require("@/transformers/resources/UserResource");
|
|
22
|
-
const axios_1 = require("@/common/utils/axios");
|
|
23
|
-
const AdminRepository_1 = require("@/repositories/AdminRepository");
|
|
24
|
-
const EmailProducer_1 = require("../../queues/producers/EmailProducer");
|
|
25
|
-
const validator_1 = require("@/common/utils/validator");
|
|
26
|
-
let AuthService = class AuthService {
|
|
27
|
-
userRepository;
|
|
28
|
-
adminRepository;
|
|
29
|
-
constructor() {
|
|
30
|
-
this.userRepository = new UserRepository_1.UserRepository();
|
|
31
|
-
this.adminRepository = new AdminRepository_1.AdminRepository();
|
|
32
|
-
}
|
|
33
|
-
async registerUser(req) {
|
|
34
|
-
const { email, password, full_name, phone, confirm_password, terms_and_conditions } = req;
|
|
35
|
-
let message = null;
|
|
36
|
-
if (configs_1.CONFIGS.IS_PRODUCTION) {
|
|
37
|
-
const isEmailValid = await (0, validator_1.hasValidMX)(email);
|
|
38
|
-
if (!isEmailValid) {
|
|
39
|
-
message = "Invalid email domain. Please use a valid domain.";
|
|
40
|
-
logger_1.logger.error(message);
|
|
41
|
-
throw new AppError_1.AppError(message);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (!terms_and_conditions) {
|
|
45
|
-
message = "You must accept the terms and conditions to register";
|
|
46
|
-
logger_1.logger.error(message);
|
|
47
|
-
throw new AppError_1.AppError(message);
|
|
48
|
-
}
|
|
49
|
-
if (!terms_and_conditions) {
|
|
50
|
-
message = "You must accept the terms and conditions to register";
|
|
51
|
-
logger_1.logger.error(message);
|
|
52
|
-
throw new AppError_1.AppError(message);
|
|
53
|
-
}
|
|
54
|
-
if (password !== confirm_password) {
|
|
55
|
-
message = "Password anc confirm password mismatch";
|
|
56
|
-
logger_1.logger.error(message);
|
|
57
|
-
throw new AppError_1.AppError(message);
|
|
58
|
-
}
|
|
59
|
-
const existingUser = await this.userRepository.getRepo().findOne({
|
|
60
|
-
where: [
|
|
61
|
-
{
|
|
62
|
-
email
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
phone
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
});
|
|
69
|
-
if (existingUser) {
|
|
70
|
-
message = 'Email or phone already exists';
|
|
71
|
-
throw new AppError_1.AppError(message);
|
|
72
|
-
}
|
|
73
|
-
const hashedPassword = await (0, utils_1.hashString)(password);
|
|
74
|
-
const { otp, expireAt: verification_expires_at } = (0, utils_1.generateOTP)(30);
|
|
75
|
-
const { uuid } = (0, utils_1.generateUUID)();
|
|
76
|
-
const user = await this.userRepository.create({
|
|
77
|
-
email,
|
|
78
|
-
full_name,
|
|
79
|
-
phone,
|
|
80
|
-
verification_expires_at,
|
|
81
|
-
verification_token: uuid,
|
|
82
|
-
verification_otp: otp,
|
|
83
|
-
password_hash: hashedPassword,
|
|
84
|
-
terms_and_conditions,
|
|
85
|
-
});
|
|
86
|
-
const { iv: ivHex, encryptedData } = (0, utils_1.encrypt)(email);
|
|
87
|
-
const verification_link = `${configs_1.CONFIGS.MAIN_WEBSITE_BASE_URL}/email/verification/${uuid}?hash=${ivHex}&ref=${encryptedData}`;
|
|
88
|
-
const messageBody = {
|
|
89
|
-
otp,
|
|
90
|
-
verification_link,
|
|
91
|
-
email,
|
|
92
|
-
first_name: (0, utils_1.capitalizeFirst)(full_name),
|
|
93
|
-
};
|
|
94
|
-
await (0, EmailProducer_1.sendAccountActivationEmail)(messageBody);
|
|
95
|
-
message = messages_1.USER_MESSAGES.AUTH.REGISTRATION.SUCCESSFUL;
|
|
96
|
-
return {
|
|
97
|
-
successful: true,
|
|
98
|
-
data: { user: UserResource_1.UserResource.userToJSON(user) },
|
|
99
|
-
message,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async loginUser(req) {
|
|
103
|
-
const { email, password } = req;
|
|
104
|
-
const existingUser = await this.userRepository.findOneAndRelations({
|
|
105
|
-
where: { email },
|
|
106
|
-
relations: ["plan"],
|
|
107
|
-
select: [
|
|
108
|
-
'full_name',
|
|
109
|
-
'uuid',
|
|
110
|
-
'id',
|
|
111
|
-
'profile_level',
|
|
112
|
-
'is_verified',
|
|
113
|
-
'plan',
|
|
114
|
-
'email',
|
|
115
|
-
'user_status',
|
|
116
|
-
'is_verified',
|
|
117
|
-
'mode_of_sign_up',
|
|
118
|
-
'password_hash'
|
|
119
|
-
]
|
|
120
|
-
});
|
|
121
|
-
if (!existingUser) {
|
|
122
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.ACCOUNT.INVALID_CREDENTIALS);
|
|
123
|
-
}
|
|
124
|
-
const isPasswordCheckOK = await (0, utils_1.compareHash)(password, existingUser.password_hash || "");
|
|
125
|
-
if (!isPasswordCheckOK) {
|
|
126
|
-
if (!existingUser.password_hash ||
|
|
127
|
-
existingUser.mode_of_sign_up !== UserEnums_1.ONBOARDING_MEDIUM.EMAIL_PASSWORD) {
|
|
128
|
-
throw new AppError_1.AppError("We found your account but was created using a social media account!", 400);
|
|
129
|
-
}
|
|
130
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.ACCOUNT.INVALID_CREDENTIALS);
|
|
131
|
-
}
|
|
132
|
-
if (existingUser.user_status !== UserEnums_1.AccountStatus.ACTIVE || !existingUser.is_verified) {
|
|
133
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.ACCOUNT.INACTIVE_ACCOUNT);
|
|
134
|
-
}
|
|
135
|
-
const jwtDetails = (0, utils_1.generateJWT)({ email: existingUser.email,
|
|
136
|
-
user_id: existingUser.id,
|
|
137
|
-
uuid: existingUser.uuid,
|
|
138
|
-
plan: existingUser.plan }, "USER");
|
|
139
|
-
logger_1.logger.debug(messages_1.USER_MESSAGES.AUTH.LOGIN.JWT_GENERATED);
|
|
140
|
-
return {
|
|
141
|
-
isSuccess: true,
|
|
142
|
-
user: UserResource_1.UserResource.userToJSON(existingUser),
|
|
143
|
-
token: jwtDetails,
|
|
144
|
-
message: messages_1.USER_MESSAGES.AUTH.LOGIN.LOGIN_SUCCESSFUL,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
async loginWithGoolge(token) {
|
|
148
|
-
const data = await (0, axios_1.makeApiCall)("https://www.googleapis.com/oauth2/v3/userinfo", {
|
|
149
|
-
method: "GET",
|
|
150
|
-
headers: {
|
|
151
|
-
Authorization: `Bearer ${token}`,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
let user;
|
|
155
|
-
if (data && data?.email && data?.email_verified === true) {
|
|
156
|
-
user = await this.userRepository.findOneAndRelations({
|
|
157
|
-
where: { email: data?.email },
|
|
158
|
-
});
|
|
159
|
-
if (!user) {
|
|
160
|
-
if (data?.name) {
|
|
161
|
-
const [first_name] = data?.name.split(" ");
|
|
162
|
-
user = await this.userRepository.create({
|
|
163
|
-
email: data?.email,
|
|
164
|
-
full_name: data?.name,
|
|
165
|
-
user_status: UserEnums_1.AccountStatus.ACTIVE,
|
|
166
|
-
is_verified: true,
|
|
167
|
-
mode_of_sign_up: UserEnums_1.ONBOARDING_MEDIUM.GOOGLE,
|
|
168
|
-
terms_and_conditions: true,
|
|
169
|
-
});
|
|
170
|
-
const messageBody = {
|
|
171
|
-
email: data?.email,
|
|
172
|
-
first_name: (0, utils_1.capitalizeFirst)(first_name),
|
|
173
|
-
};
|
|
174
|
-
await (0, EmailProducer_1.sendWelcomeEmail)(messageBody);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
throw new AppError_1.AppError("Login with Google failed!", 400);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const jwtDetails = (0, utils_1.generateJWT)({ email: user.email, user_id: user.uuid }, "USER");
|
|
181
|
-
logger_1.logger.debug(messages_1.USER_MESSAGES.AUTH.LOGIN.JWT_GENERATED);
|
|
182
|
-
return {
|
|
183
|
-
successful: true,
|
|
184
|
-
data: {
|
|
185
|
-
user: UserResource_1.UserResource.userToJSON(user),
|
|
186
|
-
access_token: jwtDetails,
|
|
187
|
-
},
|
|
188
|
-
message: messages_1.USER_MESSAGES.AUTH.LOGIN.LOGIN_SUCCESSFUL,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
throw new AppError_1.AppError("Login with Google failed!", 400);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async validateEmail(req) {
|
|
196
|
-
const { verification_token, hash, ref } = req;
|
|
197
|
-
let whereConditions = {
|
|
198
|
-
verification_token,
|
|
199
|
-
};
|
|
200
|
-
const user = await this.userRepository.basicFindOneByConditions(whereConditions);
|
|
201
|
-
if (!user) {
|
|
202
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.EMAIL_VERIFICATION.INVALID, 404);
|
|
203
|
-
}
|
|
204
|
-
if (user.user_status === UserEnums_1.AccountStatus.ACTIVE) {
|
|
205
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.EMAIL_VERIFICATION.ALREADY_ACTIVATED, 404);
|
|
206
|
-
}
|
|
207
|
-
// Check if OTP has expired
|
|
208
|
-
const expectedOtpExpirationDate = user.verification_expires_at;
|
|
209
|
-
const expectedTokenExpirationDate = user.reset_token_expires_at;
|
|
210
|
-
const otpHasExpired = (0, utils_1.hasExpired)(expectedOtpExpirationDate);
|
|
211
|
-
const tokenHasExpired = (0, utils_1.hasExpired)(expectedTokenExpirationDate);
|
|
212
|
-
if (tokenHasExpired || otpHasExpired) {
|
|
213
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.EMAIL_VERIFICATION.EXPIRED, 400);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
await this.userRepository.updateOne({
|
|
217
|
-
email: user.email,
|
|
218
|
-
}, {
|
|
219
|
-
is_verified: true,
|
|
220
|
-
user_status: UserEnums_1.AccountStatus.ACTIVE,
|
|
221
|
-
verification_token: null,
|
|
222
|
-
verification_expires_at: new Date(),
|
|
223
|
-
});
|
|
224
|
-
const messageBody = {
|
|
225
|
-
email: user.email,
|
|
226
|
-
first_name: (0, utils_1.capitalizeFirst)(user.full_name),
|
|
227
|
-
};
|
|
228
|
-
await (0, EmailProducer_1.sendWelcomeEmail)(messageBody);
|
|
229
|
-
const jwtDetails = (0, utils_1.generateJWT)({ email: user.email, user_id: user.uuid }, "USER");
|
|
230
|
-
return {
|
|
231
|
-
successful: true,
|
|
232
|
-
data: {
|
|
233
|
-
user: UserResource_1.UserResource.userToJSON(user),
|
|
234
|
-
access_token: jwtDetails,
|
|
235
|
-
},
|
|
236
|
-
message: messages_1.USER_MESSAGES.EMAIL_VERIFICATION.SUCCESS,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
async validateOtp(req) {
|
|
241
|
-
const { verification_token, hash, ref } = req;
|
|
242
|
-
const user = await this.userRepository.basicFindOneByConditions({
|
|
243
|
-
verification_otp: verification_token,
|
|
244
|
-
verification_token: hash
|
|
245
|
-
});
|
|
246
|
-
if (!user) {
|
|
247
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.EMAIL_VERIFICATION.INVALID, 404);
|
|
248
|
-
}
|
|
249
|
-
if (user.user_status === UserEnums_1.AccountStatus.ACTIVE) {
|
|
250
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.EMAIL_VERIFICATION.ALREADY_ACTIVATED, 404);
|
|
251
|
-
}
|
|
252
|
-
// Check if OTP has expired
|
|
253
|
-
const expectedOtpExpirationDate = user.verification_expires_at;
|
|
254
|
-
const expectedTokenExpirationDate = user.reset_token_expires_at;
|
|
255
|
-
const otpHasExpired = (0, utils_1.hasExpired)(expectedOtpExpirationDate);
|
|
256
|
-
const tokenHasExpired = (0, utils_1.hasExpired)(expectedTokenExpirationDate);
|
|
257
|
-
if (tokenHasExpired || otpHasExpired) {
|
|
258
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.EMAIL_VERIFICATION.EXPIRED, 400);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
await this.userRepository.updateOne({
|
|
262
|
-
email: user.email,
|
|
263
|
-
}, {
|
|
264
|
-
is_verified: true,
|
|
265
|
-
user_status: UserEnums_1.AccountStatus.ACTIVE,
|
|
266
|
-
verification_token: null,
|
|
267
|
-
verification_otp: null,
|
|
268
|
-
verification_expires_at: new Date(),
|
|
269
|
-
});
|
|
270
|
-
const messageBody = {
|
|
271
|
-
email: user.email,
|
|
272
|
-
first_name: (0, utils_1.capitalizeFirst)(user.full_name),
|
|
273
|
-
};
|
|
274
|
-
await (0, EmailProducer_1.sendWelcomeEmail)(messageBody);
|
|
275
|
-
const jwtDetails = (0, utils_1.generateJWT)({ email: user.email,
|
|
276
|
-
user_id: user.id,
|
|
277
|
-
uuid: user.uuid,
|
|
278
|
-
plan: user.plan }, "USER");
|
|
279
|
-
return {
|
|
280
|
-
successful: true,
|
|
281
|
-
data: {
|
|
282
|
-
user: UserResource_1.UserResource.userToJSON(user),
|
|
283
|
-
access_token: jwtDetails,
|
|
284
|
-
},
|
|
285
|
-
message: messages_1.USER_MESSAGES.EMAIL_VERIFICATION.SUCCESS,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
async loginAdminUser(req) {
|
|
290
|
-
const { email, password } = req;
|
|
291
|
-
const existingUser = await this.adminRepository.findOneAndRelations({
|
|
292
|
-
where: { email },
|
|
293
|
-
});
|
|
294
|
-
if (!existingUser) {
|
|
295
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.ACCOUNT.INVALID_CREDENTIALS);
|
|
296
|
-
}
|
|
297
|
-
const isPasswordCheckOK = await (0, utils_1.compareHash)(password, existingUser.password_hash);
|
|
298
|
-
if (!isPasswordCheckOK) {
|
|
299
|
-
throw new AppError_1.AppError(messages_1.USER_MESSAGES.ACCOUNT.INVALID_CREDENTIALS);
|
|
300
|
-
}
|
|
301
|
-
const jwtDetails = (0, utils_1.generateJWT)({ email: existingUser.email, user_id: existingUser.uuid }, "ADMIN");
|
|
302
|
-
logger_1.logger.debug(messages_1.USER_MESSAGES.AUTH.LOGIN.JWT_GENERATED);
|
|
303
|
-
const user = UserResource_1.UserResource.adminUserToJSON(existingUser);
|
|
304
|
-
return {
|
|
305
|
-
successful: true,
|
|
306
|
-
data: {
|
|
307
|
-
...user,
|
|
308
|
-
token: jwtDetails
|
|
309
|
-
},
|
|
310
|
-
message: messages_1.USER_MESSAGES.AUTH.LOGIN.LOGIN_SUCCESSFUL,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
async resendAccountActivationMail(req) {
|
|
314
|
-
const { email } = req;
|
|
315
|
-
let message = null;
|
|
316
|
-
const existingUser = await this.userRepository.basicFindOneByConditions({
|
|
317
|
-
email,
|
|
318
|
-
});
|
|
319
|
-
if (!existingUser) {
|
|
320
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Account");
|
|
321
|
-
throw new AppError_1.AppError(message);
|
|
322
|
-
}
|
|
323
|
-
if (existingUser.user_status == UserEnums_1.AccountStatus.INACTIVE) {
|
|
324
|
-
message = "Account is inactive";
|
|
325
|
-
logger_1.logger.error(message);
|
|
326
|
-
throw new AppError_1.AppError(message);
|
|
327
|
-
}
|
|
328
|
-
if (existingUser.user_status == UserEnums_1.AccountStatus.SUSPENDED) {
|
|
329
|
-
message = "Account is was suspended";
|
|
330
|
-
logger_1.logger.error(message);
|
|
331
|
-
throw new AppError_1.AppError(message);
|
|
332
|
-
}
|
|
333
|
-
if (existingUser.user_status == UserEnums_1.AccountStatus.BANNED) {
|
|
334
|
-
message = "Account was banned";
|
|
335
|
-
logger_1.logger.error(message);
|
|
336
|
-
throw new AppError_1.AppError(message);
|
|
337
|
-
}
|
|
338
|
-
const { full_name, uuid: userUUid } = existingUser;
|
|
339
|
-
const { otp, expireAt: otp_expires_at } = (0, utils_1.generateOTP)(30);
|
|
340
|
-
const { uuid } = (0, utils_1.generateUUID)();
|
|
341
|
-
await this.userRepository.updateOne({ email, uuid: userUUid }, {
|
|
342
|
-
verification_token: uuid,
|
|
343
|
-
verification_otp: otp,
|
|
344
|
-
verification_expires_at: otp_expires_at
|
|
345
|
-
});
|
|
346
|
-
const verification_link = `${configs_1.CONFIGS.MAIN_WEBSITE_BASE_URL}/email/verification/${uuid}`;
|
|
347
|
-
const messageBody = {
|
|
348
|
-
otp,
|
|
349
|
-
verification_link,
|
|
350
|
-
email,
|
|
351
|
-
first_name: (0, utils_1.capitalizeFirst)(full_name),
|
|
352
|
-
};
|
|
353
|
-
await (0, EmailProducer_1.sendAccountActivationEmail)(messageBody);
|
|
354
|
-
message = `Account activation link was resent to ${email}`;
|
|
355
|
-
return { successful: true, data: null, message };
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
AuthService = __decorate([
|
|
359
|
-
(0, typedi_1.Service)(),
|
|
360
|
-
__metadata("design:paramtypes", [])
|
|
361
|
-
], AuthService);
|
|
362
|
-
exports.default = AuthService;
|
|
@@ -1,267 +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 BusinessRepository_1 = require("@/repositories/BusinessRepository");
|
|
20
|
-
const UploadService_1 = __importDefault(require("./UploadService"));
|
|
21
|
-
const UploadEnum_1 = require("@/common/enums/UploadEnum");
|
|
22
|
-
const Paginator_1 = require("@/transformers/Paginator");
|
|
23
|
-
const BusinessIdCategoryRepository_1 = require("@/repositories/BusinessIdCategoryRepository");
|
|
24
|
-
const BusinessCategoryRepository_1 = require("@/repositories/BusinessCategoryRepository");
|
|
25
|
-
const configs_1 = require("@/common/configs");
|
|
26
|
-
const BusinessCollection_1 = require("@/transformers/collections/BusinessCollection");
|
|
27
|
-
const BusinessResource_1 = require("@/transformers/resources/BusinessResource");
|
|
28
|
-
const MarketplaceEnum_1 = require("@/common/enums/MarketplaceEnum");
|
|
29
|
-
let BusinessService = class BusinessService {
|
|
30
|
-
businessRepository;
|
|
31
|
-
uploadService;
|
|
32
|
-
businessCategoryRepository;
|
|
33
|
-
businessIdCategoryRepository;
|
|
34
|
-
constructor() {
|
|
35
|
-
this.businessRepository = new BusinessRepository_1.BusinessRepository();
|
|
36
|
-
this.businessIdCategoryRepository = new BusinessIdCategoryRepository_1.BusinessIdCategoryRepository();
|
|
37
|
-
this.businessCategoryRepository = new BusinessCategoryRepository_1.BusinessCategoryRepository();
|
|
38
|
-
this.uploadService = new UploadService_1.default();
|
|
39
|
-
}
|
|
40
|
-
async createBusiness(businessData, user_id) {
|
|
41
|
-
let message;
|
|
42
|
-
const { business_name, category, business_id_category, business_id_image, location, description, } = businessData;
|
|
43
|
-
if (!business_id_image) {
|
|
44
|
-
message = "Business ID image is required!";
|
|
45
|
-
logger_1.logger.info(message);
|
|
46
|
-
throw new AppError_1.AppError(message, 422);
|
|
47
|
-
}
|
|
48
|
-
const businessCategory = await this.businessCategoryRepository.getRepo().findOne({
|
|
49
|
-
select: ['name', 'uuid', 'id'],
|
|
50
|
-
where: {
|
|
51
|
-
uuid: category
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
if (!businessCategory) {
|
|
55
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business category");
|
|
56
|
-
logger_1.logger.info(message);
|
|
57
|
-
throw new AppError_1.AppError(message, 404);
|
|
58
|
-
}
|
|
59
|
-
const businessIdCategory = await this.businessIdCategoryRepository.getRepo().findOne({
|
|
60
|
-
select: ['name', 'uuid', 'id'],
|
|
61
|
-
where: {
|
|
62
|
-
uuid: business_id_category
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (!businessIdCategory) {
|
|
66
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business ID category");
|
|
67
|
-
logger_1.logger.info(message);
|
|
68
|
-
throw new AppError_1.AppError(message, 404);
|
|
69
|
-
}
|
|
70
|
-
const createdBusiness = await this.businessRepository.createWithCoordinates({
|
|
71
|
-
name: business_name,
|
|
72
|
-
category_id: businessCategory.id,
|
|
73
|
-
business_id_category_id: businessIdCategory.id,
|
|
74
|
-
location,
|
|
75
|
-
description,
|
|
76
|
-
user_id
|
|
77
|
-
}, location.longitude, location.latitude);
|
|
78
|
-
const businessId = createdBusiness.identifiers?.[0]?.id;
|
|
79
|
-
logger_1.logger.info("Business created without ID image");
|
|
80
|
-
const uploadedFile = await this.uploadService.uploadImage(business_id_image, businessId, UploadEnum_1.UploadDirectories.BUSINESS_IMAGES, "BusinessModel");
|
|
81
|
-
await this.businessRepository.updateOne({
|
|
82
|
-
id: businessId,
|
|
83
|
-
user_id,
|
|
84
|
-
}, {
|
|
85
|
-
business_id_image_id: uploadedFile.id
|
|
86
|
-
});
|
|
87
|
-
logger_1.logger.info("Business ID image successfully added");
|
|
88
|
-
return {
|
|
89
|
-
successful: true,
|
|
90
|
-
data: null,
|
|
91
|
-
message: "Business created successfully"
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async getBusinessCreationData() {
|
|
95
|
-
const business_categories = await this.businessCategoryRepository.getRepo().find({
|
|
96
|
-
select: ['name', 'uuid']
|
|
97
|
-
});
|
|
98
|
-
const business_id_categories = await this.businessIdCategoryRepository.getRepo().find({
|
|
99
|
-
select: ['name', 'uuid']
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
successful: true,
|
|
103
|
-
data: {
|
|
104
|
-
business_id_categories,
|
|
105
|
-
business_categories
|
|
106
|
-
},
|
|
107
|
-
message: "Business creation data fetched successfully!"
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
async getOneBusiness(business_id, user_id) {
|
|
111
|
-
let message;
|
|
112
|
-
const { data } = await this.businessRepository.getOneBusiness(business_id);
|
|
113
|
-
const { raw, entities } = data;
|
|
114
|
-
if (!raw[0]) {
|
|
115
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business");
|
|
116
|
-
logger_1.logger.info(message);
|
|
117
|
-
throw new AppError_1.AppError(message, 404);
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
successful: true,
|
|
121
|
-
data: BusinessResource_1.BusinessResource.toJSON(raw[0], entities[0], user_id),
|
|
122
|
-
message: "Business fetched successfully!"
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
async getBusinesses(user_id, pageNumber) {
|
|
126
|
-
let message;
|
|
127
|
-
const page_number = pageNumber || 1;
|
|
128
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
129
|
-
const dataFetchParams = {
|
|
130
|
-
page_number,
|
|
131
|
-
limit,
|
|
132
|
-
};
|
|
133
|
-
const businesss = await this.loadPaginatedBusinesses(dataFetchParams, user_id);
|
|
134
|
-
if (!businesss) {
|
|
135
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Businesss");
|
|
136
|
-
logger_1.logger.info(message);
|
|
137
|
-
throw new AppError_1.AppError(message, 404);
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
successful: true,
|
|
141
|
-
data: businesss,
|
|
142
|
-
message: "Businesss fetched successfully!"
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
async loadPaginatedBusinesses(loadPagesDto, userId) {
|
|
146
|
-
const { data, total, perPage, page } = await this.businessRepository.loadPaginatedBusinesses(loadPagesDto, userId);
|
|
147
|
-
const { raw, entities } = data;
|
|
148
|
-
return (0, Paginator_1.paginator)({
|
|
149
|
-
total,
|
|
150
|
-
perPage,
|
|
151
|
-
currentPage: page,
|
|
152
|
-
data: BusinessCollection_1.BusinnessCollection.toJSON(raw, entities, userId),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
async updateOneBusiness(businessData, business_id, user_id) {
|
|
156
|
-
let message;
|
|
157
|
-
const { business_name, category, location, description, } = businessData;
|
|
158
|
-
const business = await this.businessRepository.basicFindOneByConditions({
|
|
159
|
-
uuid: business_id,
|
|
160
|
-
user_id
|
|
161
|
-
});
|
|
162
|
-
if (!business) {
|
|
163
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business");
|
|
164
|
-
logger_1.logger.info(message);
|
|
165
|
-
throw new AppError_1.AppError(message, 404);
|
|
166
|
-
}
|
|
167
|
-
const businessCategory = await this.businessCategoryRepository.getRepo().findOne({
|
|
168
|
-
select: ['name', 'uuid', 'id'],
|
|
169
|
-
where: {
|
|
170
|
-
uuid: category
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
if (!businessCategory) {
|
|
174
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business category");
|
|
175
|
-
logger_1.logger.info(message);
|
|
176
|
-
throw new AppError_1.AppError(message, 404);
|
|
177
|
-
}
|
|
178
|
-
await this.businessRepository.updateWithCoordinates({
|
|
179
|
-
uuid: business.uuid,
|
|
180
|
-
user_id,
|
|
181
|
-
}, {
|
|
182
|
-
name: business_name,
|
|
183
|
-
category_id: businessCategory.id,
|
|
184
|
-
location,
|
|
185
|
-
description,
|
|
186
|
-
}, location.longitude, location.latitude);
|
|
187
|
-
return {
|
|
188
|
-
successful: true,
|
|
189
|
-
data: null,
|
|
190
|
-
message: "Business updated successfully!"
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
async hideOneBusiness(business_id, user_id) {
|
|
194
|
-
let message;
|
|
195
|
-
const business = await this.businessRepository.basicFindOneByConditions({
|
|
196
|
-
uuid: business_id,
|
|
197
|
-
user_id
|
|
198
|
-
});
|
|
199
|
-
if (!business) {
|
|
200
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business");
|
|
201
|
-
logger_1.logger.info(message);
|
|
202
|
-
throw new AppError_1.AppError(message, 404);
|
|
203
|
-
}
|
|
204
|
-
await this.businessRepository.updateOne({
|
|
205
|
-
uuid: business.uuid,
|
|
206
|
-
user_id,
|
|
207
|
-
}, {
|
|
208
|
-
status: MarketplaceEnum_1.BusinessStatus.HIDDEN
|
|
209
|
-
});
|
|
210
|
-
return {
|
|
211
|
-
successful: true,
|
|
212
|
-
data: null,
|
|
213
|
-
message: "Business hidden successfully!"
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
async deleteOneBusiness(business_id, user_id) {
|
|
217
|
-
let message;
|
|
218
|
-
const business = await this.businessRepository.basicFindOneByConditions({
|
|
219
|
-
uuid: business_id,
|
|
220
|
-
user_id
|
|
221
|
-
});
|
|
222
|
-
if (!business) {
|
|
223
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business");
|
|
224
|
-
logger_1.logger.info(message);
|
|
225
|
-
throw new AppError_1.AppError(message, 404);
|
|
226
|
-
}
|
|
227
|
-
await this.uploadService.deleteFile(business?.business_id_image_id, business?.id, "image");
|
|
228
|
-
await this.businessRepository.deleteByCondition({
|
|
229
|
-
uuid: business.uuid,
|
|
230
|
-
user_id,
|
|
231
|
-
});
|
|
232
|
-
return {
|
|
233
|
-
successful: true,
|
|
234
|
-
data: null,
|
|
235
|
-
message: "Business deleted successfully!"
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
async searchBusinesses(search_string, pageNumber) {
|
|
239
|
-
let message;
|
|
240
|
-
const page_number = pageNumber || 1;
|
|
241
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
242
|
-
const offset = (page_number - 1) * limit;
|
|
243
|
-
const dataFetchParams = {
|
|
244
|
-
page_number,
|
|
245
|
-
limit,
|
|
246
|
-
metadata: {
|
|
247
|
-
search_string
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
const businesss = await this.loadPaginatedBusinesses(dataFetchParams);
|
|
251
|
-
if (!businesss) {
|
|
252
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Businesss");
|
|
253
|
-
logger_1.logger.info(message);
|
|
254
|
-
throw new AppError_1.AppError(message, 404);
|
|
255
|
-
}
|
|
256
|
-
return {
|
|
257
|
-
successful: true,
|
|
258
|
-
data: businesss,
|
|
259
|
-
message: "Businesss fetched successfully!"
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
BusinessService = __decorate([
|
|
264
|
-
(0, typedi_1.Service)(),
|
|
265
|
-
__metadata("design:paramtypes", [])
|
|
266
|
-
], BusinessService);
|
|
267
|
-
exports.default = BusinessService;
|