@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,540 +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 UserRepository_1 = require("../../repositories/UserRepository");
|
|
19
|
-
const messages_1 = require("../../common/constants/messages");
|
|
20
|
-
const EventRepository_1 = require("@/repositories/EventRepository");
|
|
21
|
-
const UploadService_1 = __importDefault(require("./UploadService"));
|
|
22
|
-
const UploadEnum_1 = require("@/common/enums/UploadEnum");
|
|
23
|
-
const EventTypeRepository_1 = require("@/repositories/EventTypeRepository");
|
|
24
|
-
const IndexEnum_1 = require("@/common/enums/IndexEnum");
|
|
25
|
-
const Paginator_1 = require("@/transformers/Paginator");
|
|
26
|
-
const configs_1 = require("@/common/configs");
|
|
27
|
-
const EventCollection_1 = require("@/transformers/collections/EventCollection");
|
|
28
|
-
const EventResource_1 = require("@/transformers/resources/EventResource");
|
|
29
|
-
const EventAttendanceRepository_1 = require("@/repositories/EventAttendanceRepository");
|
|
30
|
-
let EventService = class EventService {
|
|
31
|
-
eventRepository;
|
|
32
|
-
uploadService;
|
|
33
|
-
eventTypeRepository;
|
|
34
|
-
eventAttendanceRepository;
|
|
35
|
-
constructor() {
|
|
36
|
-
this.eventRepository = new EventRepository_1.EventRepository();
|
|
37
|
-
this.eventTypeRepository = new EventTypeRepository_1.EventTypeRepository();
|
|
38
|
-
this.uploadService = new UploadService_1.default();
|
|
39
|
-
this.eventAttendanceRepository = new EventAttendanceRepository_1.EventAttendanceRepository();
|
|
40
|
-
}
|
|
41
|
-
async createEvent(eventData, user_id) {
|
|
42
|
-
let message;
|
|
43
|
-
const { event_name, number_of_attendees, cover_image, event_type, location, date_and_time, description, event_venue, } = eventData;
|
|
44
|
-
if (!cover_image) {
|
|
45
|
-
message = "Cover image is required!";
|
|
46
|
-
logger_1.logger.info(message);
|
|
47
|
-
throw new AppError_1.AppError(message, 400);
|
|
48
|
-
}
|
|
49
|
-
const eventType = await this.eventTypeRepository.getRepo().findOne({
|
|
50
|
-
select: ['name', 'uuid', 'id'],
|
|
51
|
-
where: {
|
|
52
|
-
uuid: event_type
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
if (!eventType) {
|
|
56
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Event type");
|
|
57
|
-
logger_1.logger.info(message);
|
|
58
|
-
throw new AppError_1.AppError(message, 404);
|
|
59
|
-
}
|
|
60
|
-
const createdEvent = await this.eventRepository.createWithCoordinates({
|
|
61
|
-
name: event_name,
|
|
62
|
-
number_of_attendees,
|
|
63
|
-
type_id: eventType.id,
|
|
64
|
-
location,
|
|
65
|
-
event_venue,
|
|
66
|
-
date: date_and_time,
|
|
67
|
-
description,
|
|
68
|
-
user_id
|
|
69
|
-
}, location.longitude, location.latitude);
|
|
70
|
-
const eventId = createdEvent.identifiers?.[0]?.id;
|
|
71
|
-
logger_1.logger.info("Event created without cover image");
|
|
72
|
-
const uploadedFile = await this.uploadService.uploadImage(cover_image, eventId, UploadEnum_1.UploadDirectories.EVENTS, "EventModel");
|
|
73
|
-
logger_1.logger.info("Event cover image successfully created");
|
|
74
|
-
await this.eventRepository.updateOne({
|
|
75
|
-
uuid: createdEvent.generatedMaps?.[0]?.uuid,
|
|
76
|
-
user_id,
|
|
77
|
-
}, {
|
|
78
|
-
cover_image_id: uploadedFile.id
|
|
79
|
-
});
|
|
80
|
-
logger_1.logger.info("Event cover image added successfully");
|
|
81
|
-
await this.eventAttendanceRepository.create({
|
|
82
|
-
event_id: createdEvent.identifiers?.[0]?.id,
|
|
83
|
-
attender_id: user_id
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
successful: true,
|
|
87
|
-
data: null,
|
|
88
|
-
message: "Event created successfully"
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
async getEventCreationData() {
|
|
92
|
-
const event_types = await this.eventTypeRepository.getRepo().find({
|
|
93
|
-
select: ['name', 'uuid']
|
|
94
|
-
});
|
|
95
|
-
const attendees = IndexEnum_1.AttendeeRange;
|
|
96
|
-
return {
|
|
97
|
-
successful: true,
|
|
98
|
-
data: {
|
|
99
|
-
attendees,
|
|
100
|
-
event_types
|
|
101
|
-
},
|
|
102
|
-
message: "Event creation data fetched successfully!"
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
async getOneEvent(event_id, user_id) {
|
|
106
|
-
let message;
|
|
107
|
-
const { data } = await this.eventRepository.getOneEvent(event_id, user_id);
|
|
108
|
-
const { raw } = data;
|
|
109
|
-
if (!raw[0]) {
|
|
110
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Event");
|
|
111
|
-
logger_1.logger.info(message);
|
|
112
|
-
throw new AppError_1.AppError(message, 404);
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
successful: true,
|
|
116
|
-
data: EventResource_1.EventResource.toJSON(raw[0], user_id),
|
|
117
|
-
message: "Event fetched successfully!"
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async getEvents(user_id, pageNumber) {
|
|
121
|
-
let message;
|
|
122
|
-
const page_number = pageNumber || 1;
|
|
123
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
124
|
-
const dataFetchParams = {
|
|
125
|
-
page_number,
|
|
126
|
-
limit,
|
|
127
|
-
};
|
|
128
|
-
const events = await this.loadPaginatedEvents(dataFetchParams, user_id);
|
|
129
|
-
if (!events) {
|
|
130
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Events");
|
|
131
|
-
logger_1.logger.info(message);
|
|
132
|
-
throw new AppError_1.AppError(message, 404);
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
successful: true,
|
|
136
|
-
data: events,
|
|
137
|
-
message: "Events fetched successfully!"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async getRecommendedEvents(user_id, pageNumber) {
|
|
141
|
-
let message;
|
|
142
|
-
const page_number = pageNumber || 1;
|
|
143
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
144
|
-
const offset = (page_number - 1) * limit;
|
|
145
|
-
const userRepository = new UserRepository_1.UserRepository();
|
|
146
|
-
const existingUser = await userRepository.findOneAndRelations({
|
|
147
|
-
where: {
|
|
148
|
-
id: user_id
|
|
149
|
-
},
|
|
150
|
-
relations: ['user_profile']
|
|
151
|
-
});
|
|
152
|
-
if (!existingUser) {
|
|
153
|
-
const message = messages_1.dynamic_messages.NOT_FOUND("User");
|
|
154
|
-
logger_1.logger.info(message);
|
|
155
|
-
throw new AppError_1.AppError(message);
|
|
156
|
-
}
|
|
157
|
-
const location = existingUser?.user_profile?.location;
|
|
158
|
-
const recommendationOptions = {
|
|
159
|
-
page_number,
|
|
160
|
-
limit,
|
|
161
|
-
user_id,
|
|
162
|
-
lat: location?.coordinates?.lat,
|
|
163
|
-
lng: location?.coordinates?.long,
|
|
164
|
-
city: location?.city,
|
|
165
|
-
state: location?.state,
|
|
166
|
-
country: location?.country,
|
|
167
|
-
connections: [],
|
|
168
|
-
};
|
|
169
|
-
const events = await this.recommendEvents(recommendationOptions);
|
|
170
|
-
return {
|
|
171
|
-
successful: true,
|
|
172
|
-
data: events,
|
|
173
|
-
message: "Events fetched successfully!"
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
async getUpcomingEvents(user_id, pageNumber) {
|
|
177
|
-
let message;
|
|
178
|
-
const page_number = pageNumber || 1;
|
|
179
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
180
|
-
const offset = (page_number - 1) * limit;
|
|
181
|
-
const userRepository = new UserRepository_1.UserRepository();
|
|
182
|
-
const existingUser = await userRepository.findOneAndRelations({
|
|
183
|
-
where: {
|
|
184
|
-
id: user_id
|
|
185
|
-
},
|
|
186
|
-
relations: ['user_profile']
|
|
187
|
-
});
|
|
188
|
-
if (!existingUser) {
|
|
189
|
-
const message = messages_1.dynamic_messages.NOT_FOUND("User");
|
|
190
|
-
logger_1.logger.info(message);
|
|
191
|
-
throw new AppError_1.AppError(message);
|
|
192
|
-
}
|
|
193
|
-
const location = existingUser?.user_profile?.location;
|
|
194
|
-
// const upcomingOptions: RecommendationOptions = {
|
|
195
|
-
// page_number,
|
|
196
|
-
// limit,
|
|
197
|
-
// user_id,
|
|
198
|
-
// lat: location?.coordinates?.lat,
|
|
199
|
-
// lng:location?.coordinates?.long,
|
|
200
|
-
// city: location?.city,
|
|
201
|
-
// state: location?.state,
|
|
202
|
-
// country: location?.country,
|
|
203
|
-
// connections: [],
|
|
204
|
-
// };
|
|
205
|
-
// const events = await this.upcomingEvents(upcomingOptions)
|
|
206
|
-
const dataFetchParams = {
|
|
207
|
-
page_number,
|
|
208
|
-
limit,
|
|
209
|
-
metadata: {
|
|
210
|
-
upcoming_event: true
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
const events = await this.loadPaginatedEvents(dataFetchParams);
|
|
214
|
-
if (!events) {
|
|
215
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Events");
|
|
216
|
-
logger_1.logger.info(message);
|
|
217
|
-
throw new AppError_1.AppError(message, 404);
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
successful: true,
|
|
221
|
-
data: events,
|
|
222
|
-
message: "Events fetched successfully!"
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
async loadPaginatedEvents(loadPagesDto, userId) {
|
|
226
|
-
const { data, total, perPage, page } = await this.eventRepository.loadPaginatedEvents(loadPagesDto, userId);
|
|
227
|
-
const { raw } = data;
|
|
228
|
-
return (0, Paginator_1.paginator)({
|
|
229
|
-
total,
|
|
230
|
-
perPage,
|
|
231
|
-
currentPage: page,
|
|
232
|
-
data: EventCollection_1.EventCollection.toJSON(raw, userId),
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
async updateOneEvent(eventData, event_id, user_id) {
|
|
236
|
-
let message;
|
|
237
|
-
const { event_name, number_of_attendees, cover_image, event_type, location, date_and_time, description, event_venue, } = eventData;
|
|
238
|
-
let optionalFieldsToUpdate = {};
|
|
239
|
-
const event = await this.eventRepository.basicFindOneByConditions({
|
|
240
|
-
uuid: event_id,
|
|
241
|
-
user_id
|
|
242
|
-
});
|
|
243
|
-
if (!event) {
|
|
244
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Event");
|
|
245
|
-
logger_1.logger.info(message);
|
|
246
|
-
throw new AppError_1.AppError(message, 404);
|
|
247
|
-
}
|
|
248
|
-
const eventType = await this.eventTypeRepository.getRepo().findOne({
|
|
249
|
-
select: ['name', 'uuid', 'id'],
|
|
250
|
-
where: {
|
|
251
|
-
uuid: event_type
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
if (!eventType) {
|
|
255
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Event type");
|
|
256
|
-
logger_1.logger.info(message);
|
|
257
|
-
throw new AppError_1.AppError(message, 404);
|
|
258
|
-
}
|
|
259
|
-
if (cover_image) {
|
|
260
|
-
await this.uploadService.deleteFile(event?.cover_image_id, event?.id, "image");
|
|
261
|
-
const uploadedFile = await this.uploadService.uploadImage(cover_image, event?.id, UploadEnum_1.UploadDirectories.EVENTS, "EventModel");
|
|
262
|
-
optionalFieldsToUpdate.cover_image_id = uploadedFile.id;
|
|
263
|
-
}
|
|
264
|
-
await this.eventRepository.updateWithCoordinates({
|
|
265
|
-
uuid: event.uuid,
|
|
266
|
-
user_id,
|
|
267
|
-
}, {
|
|
268
|
-
name: event_name,
|
|
269
|
-
number_of_attendees,
|
|
270
|
-
type_id: eventType.id,
|
|
271
|
-
location,
|
|
272
|
-
event_venue,
|
|
273
|
-
date: date_and_time,
|
|
274
|
-
description,
|
|
275
|
-
...optionalFieldsToUpdate,
|
|
276
|
-
}, location.longitude, location.latitude);
|
|
277
|
-
return {
|
|
278
|
-
successful: true,
|
|
279
|
-
data: EventResource_1.EventResource.toJSON(event),
|
|
280
|
-
message: "Event updated successfully!"
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
async deleteOneEvent(event_id, user_id) {
|
|
284
|
-
let message;
|
|
285
|
-
const event = await this.eventRepository.basicFindOneByConditions({
|
|
286
|
-
uuid: event_id,
|
|
287
|
-
user_id
|
|
288
|
-
});
|
|
289
|
-
if (!event) {
|
|
290
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Event");
|
|
291
|
-
logger_1.logger.info(message);
|
|
292
|
-
throw new AppError_1.AppError(message, 404);
|
|
293
|
-
}
|
|
294
|
-
await this.uploadService.deleteFile(event?.cover_image_id, event?.id, "image");
|
|
295
|
-
await this.eventRepository.deleteByCondition({
|
|
296
|
-
uuid: event.uuid,
|
|
297
|
-
user_id,
|
|
298
|
-
});
|
|
299
|
-
return {
|
|
300
|
-
successful: true,
|
|
301
|
-
data: EventResource_1.EventResource.toJSON(event),
|
|
302
|
-
message: "Event deleted successfully!"
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
async searchEvents(search_string, pageNumber) {
|
|
306
|
-
let message;
|
|
307
|
-
const page_number = pageNumber || 1;
|
|
308
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
309
|
-
const offset = (page_number - 1) * limit;
|
|
310
|
-
const dataFetchParams = {
|
|
311
|
-
page_number,
|
|
312
|
-
limit,
|
|
313
|
-
metadata: {
|
|
314
|
-
search_string
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
const events = await this.loadPaginatedEvents(dataFetchParams);
|
|
318
|
-
if (!events) {
|
|
319
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Events");
|
|
320
|
-
logger_1.logger.info(message);
|
|
321
|
-
throw new AppError_1.AppError(message, 404);
|
|
322
|
-
}
|
|
323
|
-
return {
|
|
324
|
-
successful: true,
|
|
325
|
-
data: events,
|
|
326
|
-
message: "Events fetched successfully!"
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
async eventsHostedMe(user_id, pageNumber) {
|
|
330
|
-
let message;
|
|
331
|
-
const page_number = pageNumber || 1;
|
|
332
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
333
|
-
const dataFetchParams = {
|
|
334
|
-
page_number,
|
|
335
|
-
limit,
|
|
336
|
-
metadata: {
|
|
337
|
-
user_id
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const events = await this.loadPaginatedEvents(dataFetchParams, user_id);
|
|
341
|
-
if (!events) {
|
|
342
|
-
message = messages_1.dynamic_messages.NOT_FOUND("Events");
|
|
343
|
-
logger_1.logger.info(message);
|
|
344
|
-
throw new AppError_1.AppError(message, 404);
|
|
345
|
-
}
|
|
346
|
-
return {
|
|
347
|
-
successful: true,
|
|
348
|
-
data: events,
|
|
349
|
-
message: "My hosted events fetched successfully!"
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
async recommendEvents(options) {
|
|
353
|
-
const { user_id, page_number, limit } = options;
|
|
354
|
-
const { rows, total } = await this.eventRepository.getRecommendedEvents(options);
|
|
355
|
-
return (0, Paginator_1.paginator)({
|
|
356
|
-
total,
|
|
357
|
-
perPage: limit,
|
|
358
|
-
currentPage: page_number,
|
|
359
|
-
data: EventCollection_1.EventCollection.toJSON(rows, user_id),
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
async upcomingEvents(options) {
|
|
363
|
-
const { user_id, lat, lng, city, state, country, connections = [], radius = configs_1.CONFIGS.LOCATION_RADIUS, // 50km
|
|
364
|
-
page_number, limit } = options;
|
|
365
|
-
const qb = this.eventRepository.getRepo().createQueryBuilder("e")
|
|
366
|
-
.leftJoinAndSelect("e.user", "u")
|
|
367
|
-
.leftJoinAndSelect("u.user_profile", "creator_profile")
|
|
368
|
-
.leftJoinAndSelect("creator_profile.avatar", "creator_avatar")
|
|
369
|
-
/* ---------------------------------
|
|
370
|
-
Events happening within 5(km) distance
|
|
371
|
-
---------------------------------- */
|
|
372
|
-
.addSelect(`
|
|
373
|
-
ST_Distance(
|
|
374
|
-
e.coordinates::geography,
|
|
375
|
-
ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography
|
|
376
|
-
)
|
|
377
|
-
`, "distance")
|
|
378
|
-
/* ---------------------------------
|
|
379
|
-
Events that have the same event type with the ones the user has attended before (continuous)
|
|
380
|
-
---------------------------------- */
|
|
381
|
-
.addSelect(`
|
|
382
|
-
COALESCE((
|
|
383
|
-
SELECT COUNT(*)::float
|
|
384
|
-
FROM event_attendance ea
|
|
385
|
-
JOIN events ev ON ev.id = ea.event_id
|
|
386
|
-
WHERE ea.attender_id = :user_id
|
|
387
|
-
AND ev.type_id = e.type_id
|
|
388
|
-
) / 5, 0)
|
|
389
|
-
`, "type_score")
|
|
390
|
-
/* ---------------------------------
|
|
391
|
-
Distance Scoring (0 → 1) of events happening around the location of the user
|
|
392
|
-
---------------------------------- */
|
|
393
|
-
.addSelect(`
|
|
394
|
-
GREATEST(
|
|
395
|
-
0,
|
|
396
|
-
1 - (
|
|
397
|
-
ST_Distance(
|
|
398
|
-
e.coordinates::geography,
|
|
399
|
-
ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography
|
|
400
|
-
) / :radius
|
|
401
|
-
)
|
|
402
|
-
)
|
|
403
|
-
`, "distance_score")
|
|
404
|
-
/* ---------------------------------
|
|
405
|
-
Location Scoring of events happening around the location(state, city and country) of the user
|
|
406
|
-
---------------------------------- */
|
|
407
|
-
.addSelect(`
|
|
408
|
-
CASE
|
|
409
|
-
WHEN e.location->>'city' = :city THEN 1
|
|
410
|
-
WHEN e.location->>'state' = :state THEN 0.6
|
|
411
|
-
WHEN e.location->>'country' = :country THEN 0.3
|
|
412
|
-
ELSE 0
|
|
413
|
-
END
|
|
414
|
-
`, "location_score")
|
|
415
|
-
/* ---------------------------------
|
|
416
|
-
Scoring of events created by a user's connection
|
|
417
|
-
---------------------------------- */
|
|
418
|
-
.addSelect(`
|
|
419
|
-
CASE
|
|
420
|
-
WHEN e.user_id = ANY(:connections)
|
|
421
|
-
THEN 1 ELSE 0
|
|
422
|
-
END
|
|
423
|
-
`, "creator_score")
|
|
424
|
-
/* ---------------------------------
|
|
425
|
-
Events the user's connection(s) will be attending
|
|
426
|
-
---------------------------------- */
|
|
427
|
-
.addSelect(`
|
|
428
|
-
COALESCE((
|
|
429
|
-
SELECT COUNT(*)::float
|
|
430
|
-
FROM event_attendance ea
|
|
431
|
-
WHERE ea.event_id = e.id
|
|
432
|
-
AND ea.attender_id = ANY(:connections)
|
|
433
|
-
) / 10, 0)
|
|
434
|
-
`, "attendance_score")
|
|
435
|
-
/* ---------------------------------
|
|
436
|
-
Time decay score
|
|
437
|
-
---------------------------------- */
|
|
438
|
-
.addSelect(`
|
|
439
|
-
GREATEST(
|
|
440
|
-
0,
|
|
441
|
-
1 - (EXTRACT(EPOCH FROM (e.date - NOW())) / 604800)
|
|
442
|
-
)
|
|
443
|
-
`, "time_score")
|
|
444
|
-
/* ---------------------------------
|
|
445
|
-
Final score (inline expressions)
|
|
446
|
-
---------------------------------- */
|
|
447
|
-
.addSelect(`
|
|
448
|
-
(
|
|
449
|
-
0.30 * COALESCE((
|
|
450
|
-
SELECT COUNT(*)::float
|
|
451
|
-
FROM event_attendance ea
|
|
452
|
-
JOIN events ev ON ev.id = ea.event_id
|
|
453
|
-
WHERE ea.attender_id = :user_id
|
|
454
|
-
AND ev.type_id = e.type_id
|
|
455
|
-
) / 5, 0)
|
|
456
|
-
+
|
|
457
|
-
0.25 * GREATEST(
|
|
458
|
-
0,
|
|
459
|
-
1 - (
|
|
460
|
-
ST_Distance(
|
|
461
|
-
e.coordinates::geography,
|
|
462
|
-
ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography
|
|
463
|
-
) / :radius
|
|
464
|
-
)
|
|
465
|
-
)
|
|
466
|
-
+
|
|
467
|
-
0.15 * CASE
|
|
468
|
-
WHEN e.location->>'city' = :city THEN 1
|
|
469
|
-
WHEN e.location->>'state' = :state THEN 0.6
|
|
470
|
-
WHEN e.location->>'country' = :country THEN 0.3
|
|
471
|
-
ELSE 0
|
|
472
|
-
END
|
|
473
|
-
+
|
|
474
|
-
0.10 * CASE
|
|
475
|
-
WHEN e.user_id = ANY(:connections) THEN 1 ELSE 0
|
|
476
|
-
END
|
|
477
|
-
+
|
|
478
|
-
0.15 * COALESCE((
|
|
479
|
-
SELECT COUNT(*)::float
|
|
480
|
-
FROM event_attendance ea
|
|
481
|
-
WHERE ea.event_id = e.id
|
|
482
|
-
AND ea.attender_id = ANY(:connections)
|
|
483
|
-
) / 10, 0)
|
|
484
|
-
+
|
|
485
|
-
0.05 * GREATEST(
|
|
486
|
-
0,
|
|
487
|
-
1 - (EXTRACT(EPOCH FROM (e.date - NOW())) / 604800)
|
|
488
|
-
)
|
|
489
|
-
)
|
|
490
|
-
`, "final_score")
|
|
491
|
-
/* ---------------------------------
|
|
492
|
-
Filter events that have not happened
|
|
493
|
-
---------------------------------- */
|
|
494
|
-
.where("e.status = 'SCHEDULED'")
|
|
495
|
-
.andWhere("e.date > NOW()")
|
|
496
|
-
.andWhere(`
|
|
497
|
-
ST_DWithin(
|
|
498
|
-
e.coordinates::geography,
|
|
499
|
-
ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography,
|
|
500
|
-
:radius
|
|
501
|
-
)
|
|
502
|
-
`)
|
|
503
|
-
.andWhere("e.deleted_at IS NULL")
|
|
504
|
-
/* ---------------------------------
|
|
505
|
-
Ordering
|
|
506
|
-
---------------------------------- */
|
|
507
|
-
.orderBy("final_score", "DESC")
|
|
508
|
-
.addOrderBy("distance", "ASC")
|
|
509
|
-
// .limit(limit)
|
|
510
|
-
.take(limit)
|
|
511
|
-
.skip(page_number)
|
|
512
|
-
/* ---------------------------------
|
|
513
|
-
Parameters
|
|
514
|
-
---------------------------------- */
|
|
515
|
-
.setParameters({
|
|
516
|
-
user_id,
|
|
517
|
-
lat,
|
|
518
|
-
lng,
|
|
519
|
-
city,
|
|
520
|
-
state,
|
|
521
|
-
country,
|
|
522
|
-
connections,
|
|
523
|
-
radius,
|
|
524
|
-
});
|
|
525
|
-
const [rows, total] = await qb.getManyAndCount();
|
|
526
|
-
// const {entities, raw} = await qb.getRawAndEntities();
|
|
527
|
-
// return entities;
|
|
528
|
-
return (0, Paginator_1.paginator)({
|
|
529
|
-
total,
|
|
530
|
-
perPage: limit,
|
|
531
|
-
currentPage: page_number,
|
|
532
|
-
data: EventCollection_1.EventCollection.toJSON(rows, user_id),
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
EventService = __decorate([
|
|
537
|
-
(0, typedi_1.Service)(),
|
|
538
|
-
__metadata("design:paramtypes", [])
|
|
539
|
-
], EventService);
|
|
540
|
-
exports.default = EventService;
|
|
@@ -1,89 +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 Paginator_1 = require("@/transformers/Paginator");
|
|
14
|
-
const configs_1 = require("@/common/configs");
|
|
15
|
-
const NotificationRepository_1 = require("@/repositories/NotificationRepository");
|
|
16
|
-
const NotificationCollection_1 = require("@/transformers/collections/NotificationCollection");
|
|
17
|
-
let NotificationService = class NotificationService {
|
|
18
|
-
notificationRepository;
|
|
19
|
-
constructor() {
|
|
20
|
-
this.notificationRepository = new NotificationRepository_1.NotificationRepository();
|
|
21
|
-
}
|
|
22
|
-
async fetchAllNotifications(user_id, pageNumber) {
|
|
23
|
-
const page_number = pageNumber || 1;
|
|
24
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
25
|
-
const options = {
|
|
26
|
-
page_number,
|
|
27
|
-
limit
|
|
28
|
-
};
|
|
29
|
-
const { rows, total } = await this.notificationRepository.fetchAllNotifications(user_id, options);
|
|
30
|
-
const data = (0, Paginator_1.paginator)({
|
|
31
|
-
total,
|
|
32
|
-
perPage: limit,
|
|
33
|
-
currentPage: page_number,
|
|
34
|
-
data: NotificationCollection_1.NotificationCollection.toJSON(rows),
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
successful: true,
|
|
38
|
-
data,
|
|
39
|
-
message: `Notifications fetched successfully`
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async fetchReadNotifications(user_id, pageNumber) {
|
|
43
|
-
const page_number = pageNumber || 1;
|
|
44
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
45
|
-
const options = {
|
|
46
|
-
metadata: user_id,
|
|
47
|
-
page_number,
|
|
48
|
-
limit
|
|
49
|
-
};
|
|
50
|
-
const { rows, total } = await this.notificationRepository.fetchReadNotifications(options);
|
|
51
|
-
const data = (0, Paginator_1.paginator)({
|
|
52
|
-
total,
|
|
53
|
-
perPage: limit,
|
|
54
|
-
currentPage: page_number,
|
|
55
|
-
data: NotificationCollection_1.NotificationCollection.toJSON(rows),
|
|
56
|
-
});
|
|
57
|
-
return {
|
|
58
|
-
successful: true,
|
|
59
|
-
data,
|
|
60
|
-
message: `Notifications fetched successfully`
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async fetchUnreadNotifications(user_id, pageNumber) {
|
|
64
|
-
const page_number = pageNumber || 1;
|
|
65
|
-
const limit = configs_1.CONFIGS.DATA_FETCH_LIMIT || 10;
|
|
66
|
-
const options = {
|
|
67
|
-
metadata: user_id,
|
|
68
|
-
page_number,
|
|
69
|
-
limit
|
|
70
|
-
};
|
|
71
|
-
const { rows, total } = await this.notificationRepository.fetchUnreadNotifications(options);
|
|
72
|
-
const data = (0, Paginator_1.paginator)({
|
|
73
|
-
total,
|
|
74
|
-
perPage: limit,
|
|
75
|
-
currentPage: page_number,
|
|
76
|
-
data: NotificationCollection_1.NotificationCollection.toJSON(rows),
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
successful: true,
|
|
80
|
-
data,
|
|
81
|
-
message: `Notifications fetched successfully`
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
NotificationService = __decorate([
|
|
86
|
-
(0, typedi_1.Service)(),
|
|
87
|
-
__metadata("design:paramtypes", [])
|
|
88
|
-
], NotificationService);
|
|
89
|
-
exports.default = NotificationService;
|