-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Xitija/main
PS - 1400 Time zone conversion and fetch from env
- Loading branch information
Showing
13 changed files
with
429 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ lerna-debug.log* | |
|
||
# environment | ||
.env | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common'; | ||
import { Response, Request } from 'express'; | ||
import { | ||
ExceptionFilter, | ||
Catch, | ||
ArgumentsHost, | ||
HttpException, | ||
} from '@nestjs/common'; | ||
import { Response } from 'express'; | ||
import APIResponse from '../utils/response'; | ||
import { ERROR_MESSAGES } from '../utils/constants.util'; | ||
|
||
@Catch() | ||
export class AllExceptionsFilter implements ExceptionFilter { | ||
constructor(private readonly apiId?: string) { } | ||
constructor(private readonly apiId?: string) {} | ||
|
||
catch(exception: unknown, host: ArgumentsHost) { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
const status = exception instanceof HttpException ? exception.getStatus() : 500; | ||
const exceptionResponse = exception instanceof HttpException ? exception.getResponse() : null; | ||
const errorMessage = | ||
exception instanceof HttpException | ||
? (exceptionResponse as any).message || exception.message | ||
: ERROR_MESSAGES.INTERNAL_SERVER_ERROR; | ||
const detailedErrorMessage = `${errorMessage}`; | ||
console.log('detailedErrorMessage', detailedErrorMessage); | ||
const errorResponse = APIResponse.error( | ||
this.apiId, | ||
detailedErrorMessage, | ||
exception instanceof HttpException ? exception.name : ERROR_MESSAGES.INTERNAL_SERVER_ERROR, // error | ||
status.toString(), | ||
); | ||
return response.status(status).json(errorResponse); | ||
} | ||
catch(exception: unknown, host: ArgumentsHost) { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
const status = | ||
exception instanceof HttpException ? exception.getStatus() : 500; | ||
const exceptionResponse = | ||
exception instanceof HttpException ? exception.getResponse() : null; | ||
const errorMessage = | ||
exception instanceof HttpException | ||
? (exceptionResponse as any).message || exception.message | ||
: ERROR_MESSAGES.INTERNAL_SERVER_ERROR; | ||
const detailedErrorMessage = `${errorMessage}`; | ||
console.log('detailedErrorMessage', detailedErrorMessage); | ||
const errorResponse = APIResponse.error( | ||
this.apiId, | ||
detailedErrorMessage, | ||
exception instanceof HttpException | ||
? exception.name | ||
: ERROR_MESSAGES.INTERNAL_SERVER_ERROR, | ||
status.toString(), | ||
); | ||
return response.status(status).json(errorResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,68 @@ | ||
export const ERROR_MESSAGES = { | ||
INVALID_REQUEST: 'Invalid request', | ||
NOT_FOUND: 'Not found', | ||
UNAUTHORIZED: 'Unauthorized', | ||
FORBIDDEN: 'Forbidden', | ||
BAD_REQUEST: 'Bad request', | ||
INVALID_REQUEST_BODY: 'Invalid request body', | ||
INTERNAL_SERVER_ERROR: 'Internal Server Error', | ||
REGISTRATION_DATE_INVALID: 'Registration date must be in the future', | ||
REGISTRATION_START_DATE_BEFORE_EVENT_DATE: 'Registration start date must be before the event start date', | ||
REGISTRATION_END_DATE_BEFORE_EVENT_DATE: 'Registration end date must be on or before the event start date', | ||
REGISTRATION_START_DATE_INVALID: 'Registration start date must be in the future', | ||
REGISTRATION_END_DATE_INVALID: 'Registration end date must be in the future', | ||
REGISTRATION_START_DATE_BEFORE_END_DATE: 'Registration start date must be before registration end date', | ||
RECURRENCE_END_DATE_INVALID: 'Recurrence end date must be in the future', | ||
RECURRENCE_END_DATE_BEFORE_EVENT_DATE: 'Recurrence end date must be after the event start date', | ||
RECURRING_PATTERN_REQUIRED: 'Recurrence Pattern required for event', | ||
REGISTRATION_START_DATE_REQUIRED: 'Registration Start Date required for event', | ||
INVITEES_REQUIRED: 'Invitees required for private event', | ||
INVITEES_NOT_REQUIRED: 'Invitees not required for public event', | ||
EVENT_NOT_FOUND: 'Event not found', | ||
EVENT_ATTENDEE_NOT_FOUND: 'Event attendee not found', | ||
EVENT_ATTENDEE_HISTORY_NOT_FOUND: 'Event attendee history not found', | ||
EVENT_ATTENDEE_HISTORY_ITEM_NOT_FOUND: 'Event attendee history item not found', | ||
} | ||
INVALID_REQUEST: 'Invalid request', | ||
NOT_FOUND: 'Not found', | ||
UNAUTHORIZED: 'Unauthorized', | ||
FORBIDDEN: 'Forbidden', | ||
BAD_REQUEST: 'Bad request', | ||
INVALID_REQUEST_BODY: 'Invalid request body', | ||
INTERNAL_SERVER_ERROR: 'Internal Server Error', | ||
REGISTRATION_DATE_INVALID: 'Registration date must be in the future', | ||
REGISTRATION_START_DATE_BEFORE_EVENT_DATE: | ||
'Registration start date must be before the event start date', | ||
REGISTRATION_END_DATE_BEFORE_EVENT_DATE: | ||
'Registration end date must be on or before the event start date', | ||
REGISTRATION_START_DATE_INVALID: | ||
'Registration start date must be in the future', | ||
REGISTRATION_END_DATE_INVALID: 'Registration end date must be in the future', | ||
REGISTRATION_START_DATE_BEFORE_END_DATE: | ||
'Registration start date must be before registration end date', | ||
RECURRENCE_END_DATE_INVALID: 'Recurrence end date must be in the future', | ||
RECURRENCE_END_DATE_BEFORE_EVENT_DATE: | ||
'Recurrence end date must be after the event start date', | ||
RECURRING_PATTERN_REQUIRED: 'Recurrence Pattern required for event', | ||
REGISTRATION_START_DATE_REQUIRED: | ||
'Registration Start Date required for event', | ||
RESTRICTED_EVENT_NO_REGISTRATION_DATE: | ||
'Cannot have registration date for restricted event', | ||
INVITEES_REQUIRED: 'Invitees required for private event', | ||
INVITEES_NOT_REQUIRED: 'Invitees not required for public event', | ||
EVENT_NOT_FOUND: 'Event not found', | ||
EVENT_ATTENDEE_NOT_FOUND: 'Event attendee not found', | ||
EVENT_ATTENDEE_HISTORY_NOT_FOUND: 'Event attendee history not found', | ||
EVENT_ATTENDEE_HISTORY_ITEM_NOT_FOUND: | ||
'Event attendee history item not found', | ||
}; | ||
|
||
export const SUCCESS_MESSAGES = { | ||
EVENT_CREATED: 'Event created successfully', | ||
EVENT_UPDATED: 'Event updated successfully', | ||
EVENT_DELETED: 'Event deleted successfully', | ||
EVENT_NOT_FOUND: 'Event not found', | ||
EVENT_ATTENDEE_CREATED: 'Event attendee created successfully', | ||
EVENT_ATTENDEE_UPDATED: 'Event attendee updated successfully', | ||
EVENT_ATTENDEE_DELETED: 'Event attendee deleted successfully', | ||
EVENT_ATTENDEE_HISTORY_ITEM_CREATED: 'Event attendee history item created successfully', | ||
EVENT_ATTENDEE_HISTORY_ITEM_UPDATED: 'Event attendee history item updated successfully', | ||
EVENT_ATTENDEE_HISTORY_ITEM_DELETED: 'Event attendee history item deleted successfully', | ||
} | ||
EVENT_CREATED: 'Event created successfully', | ||
EVENT_UPDATED: 'Event updated successfully', | ||
EVENT_DELETED: 'Event deleted successfully', | ||
EVENT_NOT_FOUND: 'Event not found', | ||
EVENT_ATTENDEE_CREATED: 'Event attendee created successfully', | ||
EVENT_ATTENDEE_UPDATED: 'Event attendee updated successfully', | ||
EVENT_ATTENDEE_DELETED: 'Event attendee deleted successfully', | ||
EVENT_ATTENDEE_HISTORY_ITEM_CREATED: | ||
'Event attendee history item created successfully', | ||
EVENT_ATTENDEE_HISTORY_ITEM_UPDATED: | ||
'Event attendee history item updated successfully', | ||
EVENT_ATTENDEE_HISTORY_ITEM_DELETED: | ||
'Event attendee history item deleted successfully', | ||
}; | ||
|
||
export const API_ID = { | ||
CREATE_EVENT: 'api.event.create', | ||
GET_EVENT_BY_ID: 'api.event.getbyid', | ||
GET_EVENTS: 'api.events.get', | ||
UPDATE_EVENT: 'api.event.update', | ||
DELETE_EVENT: 'api.event.delete', | ||
GET_EVENT_ATTENDEES: 'api.event.attendees.get', | ||
GET_EVENT_ATTENDEE: 'api.event.attendee.get', | ||
CREATE_EVENT_ATTENDEE: 'api.event.attendee.create', | ||
UPDATE_EVENT_ATTENDEE: 'api.event.attendee.update', | ||
DELETE_EVENT_ATTENDEE: 'api.event.attendee.delete', | ||
GET_EVENT_ATTENDEE_HISTORY: 'api.event.attendee.history.get', | ||
GET_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.get', | ||
CREATE_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.create', | ||
UPDATE_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.update', | ||
DELETE_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.delete', | ||
} | ||
CREATE_EVENT: 'api.event.create', | ||
GET_EVENT_BY_ID: 'api.event.getbyid', | ||
GET_EVENTS: 'api.events.get', | ||
UPDATE_EVENT: 'api.event.update', | ||
DELETE_EVENT: 'api.event.delete', | ||
GET_EVENT_ATTENDEES: 'api.event.attendees.get', | ||
GET_EVENT_ATTENDEE: 'api.event.attendee.get', | ||
CREATE_EVENT_ATTENDEE: 'api.event.attendee.create', | ||
UPDATE_EVENT_ATTENDEE: 'api.event.attendee.update', | ||
DELETE_EVENT_ATTENDEE: 'api.event.attendee.delete', | ||
GET_EVENT_ATTENDEE_HISTORY: 'api.event.attendee.history.get', | ||
GET_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.get', | ||
CREATE_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.create', | ||
UPDATE_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.update', | ||
DELETE_EVENT_ATTENDEE_HISTORY_ITEM: 'api.event.attendee.history.item.delete', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { getTimezoneDate } from 'src/common/utils/pipe.util'; | ||
import { ValueTransformer } from 'typeorm'; | ||
|
||
export class TimeZoneTransformer implements ValueTransformer { | ||
// private timeZone: string; | ||
|
||
constructor(private configService: ConfigService) {} | ||
|
||
// To DB: Convert the date to UTC before saving | ||
to(entityValue: Date): Date { | ||
// if (!entityValue) return entityValue; | ||
return entityValue; | ||
} | ||
|
||
// From DB: Convert the date from UTC to the desired time zone after fetching | ||
from(databaseValue: Date): Date { | ||
if (!databaseValue) return databaseValue; | ||
return getTimezoneDate( | ||
this.configService.get<string>('TIMEZONE'), | ||
new Date(databaseValue), | ||
); | ||
} | ||
} | ||
|
Oops, something went wrong.