@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,383 +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 BusinessServiceRepository_1 = require("@/repositories/BusinessServiceRepository");
|
|
20
|
-
const UploadService_1 = __importDefault(require("./UploadService"));
|
|
21
|
-
const UploadEnum_1 = require("@/common/enums/UploadEnum");
|
|
22
|
-
const CategoryRepository_1 = require("@/repositories/CategoryRepository");
|
|
23
|
-
const BusinessRepository_1 = require("@/repositories/BusinessRepository");
|
|
24
|
-
const configs_1 = require("@/common/configs");
|
|
25
|
-
const Paginator_1 = require("@/transformers/Paginator");
|
|
26
|
-
const ServiceProviderRepository_1 = require("@/repositories/ServiceProviderRepository");
|
|
27
|
-
const IndexEnum_1 = require("@/common/enums/IndexEnum");
|
|
28
|
-
const BusinessServiceResource_1 = require("@/transformers/resources/BusinessServiceResource");
|
|
29
|
-
const BusinessServiceCollection_1 = require("@/transformers/collections/BusinessServiceCollection");
|
|
30
|
-
let BusinessServiceService = class BusinessServiceService {
|
|
31
|
-
businessServiceRepository;
|
|
32
|
-
serviceProviderRepository;
|
|
33
|
-
businessRepository;
|
|
34
|
-
uploadService;
|
|
35
|
-
categoryRepository;
|
|
36
|
-
constructor() {
|
|
37
|
-
this.businessRepository = new BusinessRepository_1.BusinessRepository();
|
|
38
|
-
this.serviceProviderRepository = new ServiceProviderRepository_1.ServiceProviderRepository();
|
|
39
|
-
this.businessServiceRepository = new BusinessServiceRepository_1.BusinessServiceRepository();
|
|
40
|
-
this.categoryRepository = new CategoryRepository_1.CategoryRepository();
|
|
41
|
-
this.uploadService = new UploadService_1.default();
|
|
42
|
-
}
|
|
43
|
-
async createService(serviceData, user_id) {
|
|
44
|
-
let message;
|
|
45
|
-
const { service_provider_profile, services } = serviceData;
|
|
46
|
-
const { business_id, category, profile_image, provider_name, years_experience, location, description } = service_provider_profile;
|
|
47
|
-
const business = await this.businessRepository.getRepo().findOne({
|
|
48
|
-
select: ['name', 'uuid', 'id'],
|
|
49
|
-
where: {
|
|
50
|
-
uuid: business_id,
|
|
51
|
-
user_id
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
if (!business) {
|
|
55
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business");
|
|
56
|
-
logger_1.logger.info(message);
|
|
57
|
-
throw new AppError_1.AppError(message, 404);
|
|
58
|
-
}
|
|
59
|
-
const serviceCategory = await this.categoryRepository.getRepo().findOne({
|
|
60
|
-
select: ['name', 'uuid', 'id'],
|
|
61
|
-
where: {
|
|
62
|
-
uuid: category
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (!serviceCategory) {
|
|
66
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Service category");
|
|
67
|
-
logger_1.logger.info(message);
|
|
68
|
-
throw new AppError_1.AppError(message, 404);
|
|
69
|
-
}
|
|
70
|
-
const createdServiceProvider = await this.serviceProviderRepository.createWithCoordinates({
|
|
71
|
-
name: provider_name,
|
|
72
|
-
business_id: business.id,
|
|
73
|
-
category_id: serviceCategory.id,
|
|
74
|
-
years_of_experience: years_experience,
|
|
75
|
-
description,
|
|
76
|
-
user_id
|
|
77
|
-
}, location.longitude, location.latitude);
|
|
78
|
-
const serviceProviderId = createdServiceProvider.identifiers?.[0]?.id;
|
|
79
|
-
logger_1.logger.info("Service provider created without image");
|
|
80
|
-
const uploadedFile = await this.uploadService.uploadImage(profile_image, serviceProviderId, UploadEnum_1.UploadDirectories.SERVICE_PROVIDERS_IMAGES, IndexEnum_1.SYS_MODELS.SERVICE_PROVIDER_MODEL);
|
|
81
|
-
await this.serviceProviderRepository.updateOne({
|
|
82
|
-
id: serviceProviderId,
|
|
83
|
-
user_id,
|
|
84
|
-
}, {
|
|
85
|
-
profile_image_id: uploadedFile.id
|
|
86
|
-
});
|
|
87
|
-
logger_1.logger.info("Service provider image successfully created");
|
|
88
|
-
if (!services) {
|
|
89
|
-
message = "Services are required";
|
|
90
|
-
logger_1.logger.error(message);
|
|
91
|
-
throw new AppError_1.AppError(message, 422);
|
|
92
|
-
}
|
|
93
|
-
services.map(async (service) => {
|
|
94
|
-
await this.businessServiceRepository.create({
|
|
95
|
-
provider_info_id: serviceProviderId,
|
|
96
|
-
name: service.service_name,
|
|
97
|
-
amount: service.amount.toString(),
|
|
98
|
-
user_id
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
successful: true,
|
|
103
|
-
data: null,
|
|
104
|
-
message: "Service created successfully"
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
async getServiceCreationData() {
|
|
108
|
-
const categories = await this.categoryRepository.getRepo().find({
|
|
109
|
-
select: ['name', 'uuid']
|
|
110
|
-
});
|
|
111
|
-
return {
|
|
112
|
-
successful: true,
|
|
113
|
-
data: {
|
|
114
|
-
categories
|
|
115
|
-
},
|
|
116
|
-
message: "Service creation data fetched successfully!"
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async getOneService(service_id, user_id) {
|
|
120
|
-
let message;
|
|
121
|
-
const { data } = await this.serviceProviderRepository.getOneServiceProvider(service_id);
|
|
122
|
-
const { raw: service } = data;
|
|
123
|
-
if (!service[0]) {
|
|
124
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Service");
|
|
125
|
-
logger_1.logger.info(message);
|
|
126
|
-
throw new AppError_1.AppError(message, 404);
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
successful: true,
|
|
130
|
-
data: BusinessServiceResource_1.BusinessServiceResource.toJSON(service[0], user_id),
|
|
131
|
-
message: "Service fetched successfully!"
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
async getServicesByCategoryId(user_id, category_id, pageNumber) {
|
|
135
|
-
let message;
|
|
136
|
-
const page_number = pageNumber || 1;
|
|
137
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
138
|
-
if (!category_id) {
|
|
139
|
-
message = "Category id is required";
|
|
140
|
-
logger_1.logger.error(message);
|
|
141
|
-
throw new AppError_1.AppError(message, 422);
|
|
142
|
-
}
|
|
143
|
-
const category = await this.categoryRepository.getRepo().findOne({
|
|
144
|
-
select: ['name', 'uuid', 'id'],
|
|
145
|
-
where: {
|
|
146
|
-
uuid: category_id
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
if (!category) {
|
|
150
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Category");
|
|
151
|
-
logger_1.logger.info(message);
|
|
152
|
-
throw new AppError_1.AppError(message, 404);
|
|
153
|
-
}
|
|
154
|
-
const dataFetchParams = {
|
|
155
|
-
page_number,
|
|
156
|
-
limit,
|
|
157
|
-
metadata: {
|
|
158
|
-
category_id: category.id
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const { data, total, perPage, page } = await this.serviceProviderRepository.loadPaginatedServicesByCategoryId(dataFetchParams);
|
|
162
|
-
const { raw } = data;
|
|
163
|
-
const services = (0, Paginator_1.paginator)({
|
|
164
|
-
total,
|
|
165
|
-
perPage,
|
|
166
|
-
currentPage: page,
|
|
167
|
-
data: BusinessServiceCollection_1.BusinessServiceCollection.toJSON(raw, user_id),
|
|
168
|
-
});
|
|
169
|
-
return {
|
|
170
|
-
successful: true,
|
|
171
|
-
data: services,
|
|
172
|
-
message: "Services fetched successfully!"
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
async getServicesByBusinessId(user_id, business_id, pageNumber) {
|
|
176
|
-
let message;
|
|
177
|
-
const page_number = pageNumber || 1;
|
|
178
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
179
|
-
if (!business_id) {
|
|
180
|
-
message = "Business id is required";
|
|
181
|
-
logger_1.logger.error(message);
|
|
182
|
-
throw new AppError_1.AppError(message, 422);
|
|
183
|
-
}
|
|
184
|
-
const business = await this.businessRepository.getRepo().findOne({
|
|
185
|
-
select: ['name', 'uuid', 'id'],
|
|
186
|
-
where: {
|
|
187
|
-
uuid: business_id,
|
|
188
|
-
user_id
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
if (!business) {
|
|
192
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Business");
|
|
193
|
-
logger_1.logger.info(message);
|
|
194
|
-
throw new AppError_1.AppError(message, 404);
|
|
195
|
-
}
|
|
196
|
-
const dataFetchParams = {
|
|
197
|
-
page_number,
|
|
198
|
-
limit,
|
|
199
|
-
metadata: {
|
|
200
|
-
business_id: business.id
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
const { data, total, perPage, page } = await this.serviceProviderRepository.loadPaginatedServicesByBusinessId(dataFetchParams);
|
|
204
|
-
const { raw } = data;
|
|
205
|
-
const services = (0, Paginator_1.paginator)({
|
|
206
|
-
total,
|
|
207
|
-
perPage,
|
|
208
|
-
currentPage: page,
|
|
209
|
-
data: BusinessServiceCollection_1.BusinessServiceCollection.toJSON(raw, user_id),
|
|
210
|
-
});
|
|
211
|
-
return {
|
|
212
|
-
successful: true,
|
|
213
|
-
data: services,
|
|
214
|
-
message: "Services fetched successfully!"
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
async getServices(user_id, pageNumber) {
|
|
218
|
-
let message;
|
|
219
|
-
const page_number = pageNumber || 1;
|
|
220
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
221
|
-
const dataFetchParams = {
|
|
222
|
-
page_number,
|
|
223
|
-
limit,
|
|
224
|
-
};
|
|
225
|
-
const { data, total, perPage, page } = await this.serviceProviderRepository.loadPaginatedServices(dataFetchParams);
|
|
226
|
-
const { raw } = data;
|
|
227
|
-
const services = (0, Paginator_1.paginator)({
|
|
228
|
-
total,
|
|
229
|
-
perPage,
|
|
230
|
-
currentPage: page,
|
|
231
|
-
data: BusinessServiceCollection_1.BusinessServiceCollection.toJSON(raw, user_id),
|
|
232
|
-
});
|
|
233
|
-
if (!services) {
|
|
234
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Services");
|
|
235
|
-
logger_1.logger.info(message);
|
|
236
|
-
throw new AppError_1.AppError(message, 404);
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
successful: true,
|
|
240
|
-
data: services,
|
|
241
|
-
message: "Services fetched successfully!"
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
async loadPaginatedServices(loadPagesDto, userId) {
|
|
245
|
-
const { data, total, perPage, page } = await this.businessServiceRepository.loadPaginatedServices(loadPagesDto, userId);
|
|
246
|
-
const { raw } = data;
|
|
247
|
-
return (0, Paginator_1.paginator)({
|
|
248
|
-
total,
|
|
249
|
-
perPage,
|
|
250
|
-
currentPage: page,
|
|
251
|
-
data: BusinessServiceCollection_1.BusinessServiceCollection.toJSON(raw, userId),
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
async updateOneService(serviceData, service_id, user_id) {
|
|
255
|
-
let message;
|
|
256
|
-
const { service_provider_profile, services } = serviceData;
|
|
257
|
-
const { profile_image, provider_name, years_experience, location, category, description } = service_provider_profile;
|
|
258
|
-
const service = await this.serviceProviderRepository.basicFindOneByConditions({
|
|
259
|
-
uuid: service_id,
|
|
260
|
-
user_id
|
|
261
|
-
});
|
|
262
|
-
if (!service) {
|
|
263
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Service");
|
|
264
|
-
logger_1.logger.info(message);
|
|
265
|
-
throw new AppError_1.AppError(message, 404);
|
|
266
|
-
}
|
|
267
|
-
const serviceCategory = await this.categoryRepository.getRepo().findOne({
|
|
268
|
-
select: ['name', 'uuid', 'id'],
|
|
269
|
-
where: {
|
|
270
|
-
uuid: category
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
if (!serviceCategory) {
|
|
274
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Service category");
|
|
275
|
-
logger_1.logger.info(message);
|
|
276
|
-
throw new AppError_1.AppError(message, 404);
|
|
277
|
-
}
|
|
278
|
-
await this.serviceProviderRepository.updateWithCoordinates({
|
|
279
|
-
uuid: service.uuid,
|
|
280
|
-
user_id,
|
|
281
|
-
}, {
|
|
282
|
-
name: provider_name,
|
|
283
|
-
category_id: serviceCategory.id,
|
|
284
|
-
years_of_experience: years_experience,
|
|
285
|
-
description,
|
|
286
|
-
}, location.longitude, location.latitude);
|
|
287
|
-
const serviceProviderId = service.id;
|
|
288
|
-
if (profile_image) {
|
|
289
|
-
if (service.profile_image_id) {
|
|
290
|
-
await this.uploadService.deleteFile(service.profile_image_id, serviceProviderId, "image");
|
|
291
|
-
}
|
|
292
|
-
const uploadedFile = await this.uploadService.uploadImage(profile_image, serviceProviderId, UploadEnum_1.UploadDirectories.SERVICE_PROVIDERS_IMAGES, IndexEnum_1.SYS_MODELS.SERVICE_PROVIDER_MODEL);
|
|
293
|
-
await this.serviceProviderRepository.updateOne({
|
|
294
|
-
id: serviceProviderId,
|
|
295
|
-
user_id,
|
|
296
|
-
}, {
|
|
297
|
-
profile_image_id: uploadedFile.id
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
if (services && services.length > 0) {
|
|
301
|
-
await this.businessServiceRepository.deleteByCondition({
|
|
302
|
-
provider_info_id: service.id,
|
|
303
|
-
user_id,
|
|
304
|
-
});
|
|
305
|
-
services.map(async (service) => {
|
|
306
|
-
await this.businessServiceRepository.create({
|
|
307
|
-
provider_info_id: serviceProviderId,
|
|
308
|
-
name: service.service_name,
|
|
309
|
-
amount: service.amount.toString(),
|
|
310
|
-
user_id
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
successful: true,
|
|
316
|
-
data: null,
|
|
317
|
-
message: "Service updated successfully!"
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
async deleteOneService(service_id, user_id) {
|
|
321
|
-
let message;
|
|
322
|
-
const service = await this.serviceProviderRepository.basicFindOneByConditions({
|
|
323
|
-
uuid: service_id,
|
|
324
|
-
user_id
|
|
325
|
-
});
|
|
326
|
-
if (!service) {
|
|
327
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Service");
|
|
328
|
-
logger_1.logger.info(message);
|
|
329
|
-
throw new AppError_1.AppError(message, 404);
|
|
330
|
-
}
|
|
331
|
-
await this.serviceProviderRepository.deleteByCondition({
|
|
332
|
-
uuid: service.uuid,
|
|
333
|
-
user_id,
|
|
334
|
-
});
|
|
335
|
-
await this.businessServiceRepository.deleteByCondition({
|
|
336
|
-
provider_info_id: service.id,
|
|
337
|
-
user_id,
|
|
338
|
-
});
|
|
339
|
-
if (service.profile_image_id) {
|
|
340
|
-
await this.uploadService.deleteFile(service.profile_image_id, service.id, "image");
|
|
341
|
-
}
|
|
342
|
-
return {
|
|
343
|
-
successful: true,
|
|
344
|
-
data: null,
|
|
345
|
-
message: "Service deleted successfully!"
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
async searchServices(search_string, user_id, pageNumber) {
|
|
349
|
-
let message;
|
|
350
|
-
const page_number = pageNumber || 1;
|
|
351
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
352
|
-
const dataFetchParams = {
|
|
353
|
-
page_number,
|
|
354
|
-
limit,
|
|
355
|
-
metadata: {
|
|
356
|
-
search_string
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
const { data, total, perPage, page } = await this.serviceProviderRepository.loadPaginatedServicesSearchResults(dataFetchParams);
|
|
360
|
-
const { raw } = data;
|
|
361
|
-
const services = (0, Paginator_1.paginator)({
|
|
362
|
-
total,
|
|
363
|
-
perPage,
|
|
364
|
-
currentPage: page,
|
|
365
|
-
data: BusinessServiceCollection_1.BusinessServiceCollection.toJSON(raw, user_id),
|
|
366
|
-
});
|
|
367
|
-
if (!services) {
|
|
368
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Services");
|
|
369
|
-
logger_1.logger.info(message);
|
|
370
|
-
throw new AppError_1.AppError(message, 404);
|
|
371
|
-
}
|
|
372
|
-
return {
|
|
373
|
-
successful: true,
|
|
374
|
-
data: services,
|
|
375
|
-
message: "Services fetched successfully!"
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
BusinessServiceService = __decorate([
|
|
380
|
-
(0, typedi_1.Service)(),
|
|
381
|
-
__metadata("design:paramtypes", [])
|
|
382
|
-
], BusinessServiceService);
|
|
383
|
-
exports.default = BusinessServiceService;
|
|
@@ -1,249 +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 CardRepository_1 = require("@/repositories/CardRepository");
|
|
19
|
-
const messages_1 = require("@/common/constants/messages");
|
|
20
|
-
const CardCollection_1 = require("@/transformers/collections/CardCollection");
|
|
21
|
-
const CardResource_1 = require("@/transformers/resources/CardResource");
|
|
22
|
-
const typeorm_1 = require("typeorm");
|
|
23
|
-
const PaymentGatewayCustomerRepository_1 = require("@/repositories/PaymentGatewayCustomerRepository");
|
|
24
|
-
const UserRepository_1 = require("@/repositories/UserRepository");
|
|
25
|
-
const StripeService_1 = __importDefault(require("../StripeService"));
|
|
26
|
-
let CardService = class CardService {
|
|
27
|
-
cardRepository;
|
|
28
|
-
paymentGatewayCustomerRepository;
|
|
29
|
-
userRepository;
|
|
30
|
-
stripeService;
|
|
31
|
-
constructor() {
|
|
32
|
-
this.cardRepository = new CardRepository_1.CardRepository();
|
|
33
|
-
this.paymentGatewayCustomerRepository = new PaymentGatewayCustomerRepository_1.PaymentGatewayCustomerRepository();
|
|
34
|
-
this.userRepository = new UserRepository_1.UserRepository();
|
|
35
|
-
this.stripeService = new StripeService_1.default();
|
|
36
|
-
}
|
|
37
|
-
async getMyCards(user_id) {
|
|
38
|
-
let message;
|
|
39
|
-
const existingCards = await this.cardRepository.basicFindManyByConditions({
|
|
40
|
-
user_id
|
|
41
|
-
});
|
|
42
|
-
return {
|
|
43
|
-
successful: true,
|
|
44
|
-
data: CardCollection_1.CardCollection.toJSON(existingCards),
|
|
45
|
-
message: messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("Cards"),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
async getMyCard(user_id, card_id) {
|
|
49
|
-
let message;
|
|
50
|
-
const existingCard = await this.cardRepository.basicFindOneByConditions({
|
|
51
|
-
user_id,
|
|
52
|
-
uuid: card_id
|
|
53
|
-
});
|
|
54
|
-
if (!existingCard) {
|
|
55
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Card");
|
|
56
|
-
throw new AppError_1.AppError(message);
|
|
57
|
-
}
|
|
58
|
-
message = messages_1.dynamic_messages.FETCHED_SUCCESSFULLY("Card");
|
|
59
|
-
return {
|
|
60
|
-
successful: true,
|
|
61
|
-
data: CardResource_1.CardResource.toJSON(existingCard),
|
|
62
|
-
message: message,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async setDefaultCard(user_id, card_id) {
|
|
66
|
-
let message;
|
|
67
|
-
const existingCard = await this.cardRepository.basicFindOneByConditions({
|
|
68
|
-
user_id,
|
|
69
|
-
uuid: card_id
|
|
70
|
-
});
|
|
71
|
-
if (!existingCard) {
|
|
72
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Card");
|
|
73
|
-
throw new AppError_1.AppError(message);
|
|
74
|
-
}
|
|
75
|
-
if (existingCard.is_default) {
|
|
76
|
-
message = "Card is already default";
|
|
77
|
-
throw new AppError_1.AppError(message);
|
|
78
|
-
}
|
|
79
|
-
const defaultCard = await this.cardRepository.basicFindOneByConditions({
|
|
80
|
-
user_id,
|
|
81
|
-
is_default: true
|
|
82
|
-
});
|
|
83
|
-
if (defaultCard) {
|
|
84
|
-
defaultCard.is_default = false;
|
|
85
|
-
await this.cardRepository.updateOne({ id: defaultCard.id }, {
|
|
86
|
-
is_default: false
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
await this.cardRepository.updateOne({ id: existingCard.id }, {
|
|
90
|
-
is_default: true
|
|
91
|
-
});
|
|
92
|
-
message = "Card set as default successfully";
|
|
93
|
-
return {
|
|
94
|
-
successful: true,
|
|
95
|
-
data: CardResource_1.CardResource.toJSON(existingCard),
|
|
96
|
-
message: message,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
async addCard(webhookEvent) {
|
|
100
|
-
let message;
|
|
101
|
-
let is_default = false;
|
|
102
|
-
let addedcard;
|
|
103
|
-
const stripeCustomer = await this.paymentGatewayCustomerRepository.basicFindOneByConditions({ customer_id: webhookEvent?.customer });
|
|
104
|
-
if (!stripeCustomer) {
|
|
105
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Stripe customer");
|
|
106
|
-
logger_1.logger.error(message);
|
|
107
|
-
throw new AppError_1.AppError(message);
|
|
108
|
-
}
|
|
109
|
-
const defaultCard = await this.cardRepository.basicFindOneByConditions({
|
|
110
|
-
user_id: stripeCustomer.user_id,
|
|
111
|
-
is_default: true
|
|
112
|
-
});
|
|
113
|
-
if (!defaultCard) {
|
|
114
|
-
is_default = true;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
is_default = false;
|
|
118
|
-
}
|
|
119
|
-
addedcard = await this.cardRepository.create({
|
|
120
|
-
is_default,
|
|
121
|
-
payment_method_id: webhookEvent?.id,
|
|
122
|
-
brand: webhookEvent?.card?.brand.toUpperCase(),
|
|
123
|
-
last4_digits: webhookEvent?.card?.last4,
|
|
124
|
-
customer_id: webhookEvent?.customer,
|
|
125
|
-
name: `CARD - ${webhookEvent?.card?.brand.toUpperCase()} - ${webhookEvent?.card?.exp_month + '/' + webhookEvent?.card?.exp_year}`,
|
|
126
|
-
expiration: webhookEvent?.card?.exp_month + '/' + webhookEvent?.card?.exp_year,
|
|
127
|
-
funding: webhookEvent?.card?.funding,
|
|
128
|
-
country: webhookEvent?.card?.country,
|
|
129
|
-
user_id: stripeCustomer.user_id
|
|
130
|
-
});
|
|
131
|
-
message = "Card added successfully";
|
|
132
|
-
logger_1.logger.debug(message);
|
|
133
|
-
return {
|
|
134
|
-
successful: true,
|
|
135
|
-
data: CardResource_1.CardResource.toJSON(addedcard),
|
|
136
|
-
message: message,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
async deleteMyCard(user_id, card_id) {
|
|
140
|
-
let message;
|
|
141
|
-
const existingCard = await this.cardRepository.basicFindOneByConditions({
|
|
142
|
-
user_id,
|
|
143
|
-
uuid: card_id
|
|
144
|
-
});
|
|
145
|
-
if (!existingCard) {
|
|
146
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Card");
|
|
147
|
-
throw new AppError_1.AppError(message);
|
|
148
|
-
}
|
|
149
|
-
const otherCards = await this.cardRepository.basicFindManyByConditions({
|
|
150
|
-
user_id,
|
|
151
|
-
id: (0, typeorm_1.Not)(existingCard.id),
|
|
152
|
-
});
|
|
153
|
-
if (!otherCards.length) {
|
|
154
|
-
message = "You must have at least one other card to delete this card";
|
|
155
|
-
logger_1.logger.error(message);
|
|
156
|
-
throw new AppError_1.AppError(message);
|
|
157
|
-
}
|
|
158
|
-
if (existingCard.is_default) {
|
|
159
|
-
message = "You cannot delete the default card";
|
|
160
|
-
logger_1.logger.error(message);
|
|
161
|
-
throw new AppError_1.AppError(message);
|
|
162
|
-
}
|
|
163
|
-
let alreadySetDefaultCard = false;
|
|
164
|
-
for (let i = 0; i < otherCards.length; i++) {
|
|
165
|
-
if (otherCards[i].is_default) {
|
|
166
|
-
alreadySetDefaultCard = true;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (!alreadySetDefaultCard) {
|
|
170
|
-
otherCards[0].is_default = true;
|
|
171
|
-
await this.cardRepository.updateOne({ id: otherCards[0].id }, {
|
|
172
|
-
is_default: true
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
await this.cardRepository.deleteByCondition({
|
|
176
|
-
id: existingCard.id
|
|
177
|
-
});
|
|
178
|
-
message = "Card deleted successfully";
|
|
179
|
-
return {
|
|
180
|
-
successful: true,
|
|
181
|
-
data: CardResource_1.CardResource.toJSON(existingCard),
|
|
182
|
-
message: message,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
async updateCardName(user_id, card_id, card_name) {
|
|
186
|
-
let message;
|
|
187
|
-
const existingCard = await this.cardRepository.basicFindOneByConditions({
|
|
188
|
-
user_id,
|
|
189
|
-
uuid: card_id
|
|
190
|
-
});
|
|
191
|
-
if (!existingCard) {
|
|
192
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Card");
|
|
193
|
-
throw new AppError_1.AppError(message);
|
|
194
|
-
}
|
|
195
|
-
await this.cardRepository.updateOne({ id: existingCard.id }, {
|
|
196
|
-
name: card_name
|
|
197
|
-
});
|
|
198
|
-
message = "Card name updated successfully";
|
|
199
|
-
return {
|
|
200
|
-
successful: true,
|
|
201
|
-
data: CardResource_1.CardResource.toJSON(existingCard),
|
|
202
|
-
message: message,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
async addMyCard(user_id, payment_method_id) {
|
|
206
|
-
let message;
|
|
207
|
-
let customer_id;
|
|
208
|
-
if (!payment_method_id) {
|
|
209
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Payment ID");
|
|
210
|
-
logger_1.logger.error(message);
|
|
211
|
-
throw new AppError_1.AppError(message, 404);
|
|
212
|
-
}
|
|
213
|
-
const foundMerchant = await this.userRepository.basicFindOneByConditions({
|
|
214
|
-
id: user_id,
|
|
215
|
-
});
|
|
216
|
-
if (!foundMerchant) {
|
|
217
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Your account");
|
|
218
|
-
logger_1.logger.error(message);
|
|
219
|
-
throw new AppError_1.AppError(message, 404);
|
|
220
|
-
}
|
|
221
|
-
const paymentCustomer = await this.paymentGatewayCustomerRepository.basicFindOneByConditions({
|
|
222
|
-
user_id: user_id,
|
|
223
|
-
});
|
|
224
|
-
if (!paymentCustomer) {
|
|
225
|
-
logger_1.logger.info("No customer payment id found!");
|
|
226
|
-
const newStripeCustomer = await this.stripeService.createCustomer(foundMerchant);
|
|
227
|
-
if (!newStripeCustomer) {
|
|
228
|
-
message = "Unable to create your account on Stripe, try again!";
|
|
229
|
-
logger_1.logger.error(message);
|
|
230
|
-
throw new AppError_1.AppError(message, 400);
|
|
231
|
-
}
|
|
232
|
-
customer_id = newStripeCustomer.data.id;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
customer_id = paymentCustomer.customer_id;
|
|
236
|
-
}
|
|
237
|
-
await this.stripeService.attachedCardToCustomer(payment_method_id, customer_id);
|
|
238
|
-
return {
|
|
239
|
-
successful: true,
|
|
240
|
-
data: null,
|
|
241
|
-
message: "Payment ID was successfully added",
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
CardService = __decorate([
|
|
246
|
-
(0, typedi_1.Service)(),
|
|
247
|
-
__metadata("design:paramtypes", [])
|
|
248
|
-
], CardService);
|
|
249
|
-
exports.default = CardService;
|