-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: master into dynamic-environments
- Loading branch information
Showing
61 changed files
with
1,978 additions
and
443 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
19 changes: 19 additions & 0 deletions
19
migrations/20240109071854-add-lastPasswordChangedAt-to-users.js
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,19 @@ | ||
'use strict'; | ||
|
||
const tableName = 'users'; | ||
const newColumn = 'last_password_changed_at'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.addColumn(tableName, newColumn, { | ||
type: Sequelize.DATE, | ||
allowNull: true, | ||
defaultValue: null, | ||
}); | ||
}, | ||
|
||
async down(queryInterface) { | ||
await queryInterface.removeColumn(tableName, newColumn); | ||
}, | ||
}; |
20 changes: 20 additions & 0 deletions
20
migrations/20240117140256-add-unblock-account-to-mailtype-enum.js
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,20 @@ | ||
'use strict'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
up: async (queryInterface) => { | ||
await queryInterface.sequelize.query( | ||
`ALTER TYPE mail_type ADD VALUE 'unblock_account';`, | ||
); | ||
}, | ||
down: async (queryInterface) => { | ||
await queryInterface.sequelize.query( | ||
` | ||
ALTER TYPE mail_type RENAME TO mail_type_old; | ||
CREATE TYPE mail_type AS ENUM('invite_friend', 'reset_password', 'remove_account', 'deactivate_account'); | ||
ALTER TABLE mail_limits ALTER COLUMN mail_type TYPE mail_type USING mail_type::text::mail_type; | ||
DROP TYPE mail_type_old; | ||
`, | ||
); | ||
}, | ||
}; |
22 changes: 22 additions & 0 deletions
22
migrations/20240123143540-remove-files-deletion-on-user-deletion.js
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,22 @@ | ||
'use strict'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.removeConstraint('files', 'files_user_id_fkey'); | ||
}, | ||
|
||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.addConstraint('files', { | ||
fields: ['user_id'], | ||
type: 'foreign key', | ||
name: 'files_user_id_fkey', | ||
references: { | ||
table: 'users', | ||
field: 'id', | ||
}, | ||
onDelete: 'SET NULL', | ||
onUpdate: 'CASCADE', | ||
}); | ||
}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
migrations/20240213132333-create-index-parent-uuid-folders.js
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,16 @@ | ||
'use strict'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.query( | ||
`CREATE INDEX CONCURRENTLY folders_parent_uuid_index ON folders (parent_uuid)`, | ||
); | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.query( | ||
`DROP INDEX CONCURRENTLY folders_parent_uuid_index`, | ||
); | ||
}, | ||
}; |
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,25 +1,11 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
|
||
export class BaseHttpException extends Error { | ||
private readonly _statusCode: number; | ||
private readonly _code: string; | ||
|
||
constructor( | ||
message: string, | ||
statusCode = HttpStatus.INTERNAL_SERVER_ERROR, | ||
code?: string, | ||
public readonly message: string, | ||
public readonly statusCode = HttpStatus.INTERNAL_SERVER_ERROR, | ||
public readonly code?: string, | ||
) { | ||
super(message); | ||
this.message = message; | ||
this._statusCode = statusCode; | ||
this._code = code; | ||
} | ||
|
||
get statusCode(): number { | ||
return this._statusCode; | ||
} | ||
|
||
get code(): string { | ||
return this._code; | ||
} | ||
} |
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,33 @@ | ||
import { validate } from 'class-validator'; | ||
import { UuidDto } from './uuid.dto'; | ||
import { newUser } from '../../test/fixtures'; | ||
|
||
describe('UuidDto Validation', () => { | ||
const user = newUser(); | ||
|
||
it('When a valid UUID is passed, then pass', async () => { | ||
const dto = new UuidDto(); | ||
dto.id = user.uuid; | ||
|
||
const errors = await validate(dto); | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('When an invalid UUID is passed, then fail', async () => { | ||
const dto = new UuidDto(); | ||
dto.id = 'invalid_uuid_string'; | ||
|
||
const errors = await validate(dto); | ||
expect(errors.length).toBeGreaterThan(0); | ||
expect(errors[0].constraints).toHaveProperty('isUuid'); | ||
}); | ||
|
||
it('When an empty string is passed, then fail', async () => { | ||
const dto = new UuidDto(); | ||
dto.id = 'invalid-uuid'; | ||
const errors = await validate(dto); | ||
|
||
expect(errors.length).toBeGreaterThan(0); | ||
expect(errors[0].constraints).toHaveProperty('isUuid'); | ||
}); | ||
}); |
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,6 @@ | ||
import { IsUUID } from 'class-validator'; | ||
|
||
export class UuidDto { | ||
@IsUUID() | ||
id: string; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Time } from './time'; | ||
|
||
describe('Time class', () => { | ||
const fixedSystemCurrentDate = new Date('2022-01-01'); | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
jest.setSystemTime(fixedSystemCurrentDate); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
describe('now()', () => { | ||
it('When is called, then returns the current date', () => { | ||
const currentDate = Time.now(); | ||
expect(currentDate.getTime()).toBeGreaterThanOrEqual( | ||
new Date('2022-01-01').getTime(), | ||
); | ||
}); | ||
|
||
it('When is called and date is provided, then returns the date provided', () => { | ||
const initialDate = new Date('2022-02-02'); | ||
const currentDate = Time.now(initialDate); | ||
expect(currentDate).toEqual(initialDate); | ||
}); | ||
}); | ||
|
||
describe('dateWithDaysAdded()', () => { | ||
it('When days are added, then returns correct current date and days added', () => { | ||
const systemFutureDate = new Date(fixedSystemCurrentDate); | ||
systemFutureDate.setDate(systemFutureDate.getDate() + 5); | ||
|
||
const futureDate = Time.dateWithDaysAdded(5); | ||
|
||
expect(futureDate.getUTCDate()).toBe(systemFutureDate.getUTCDate()); | ||
}); | ||
}); | ||
|
||
describe('isToday()', () => { | ||
it('When provided date is today, then returns true', () => { | ||
const today = new Date(); | ||
|
||
const isToday = Time.isToday(today); | ||
|
||
expect(isToday).toBe(true); | ||
}); | ||
|
||
it('When provided date is another day, then returns false', () => { | ||
const notToday = new Date(); | ||
notToday.setDate(notToday.getDate() + 1); | ||
|
||
const isToday = Time.isToday(notToday); | ||
|
||
expect(isToday).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('convertTimestampToDate()', () => { | ||
it('When a date in timestamp is provided, then same date should be returned', () => { | ||
const timestamp = 1642531200; | ||
|
||
const timestampDate = Time.convertTimestampToDate(timestamp); | ||
|
||
expect(timestampDate).toBeInstanceOf(Date); | ||
expect(timestampDate).toEqual(new Date(timestamp * 1000)); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.