Skip to content

Commit

Permalink
add created date to user
Browse files Browse the repository at this point in the history
  • Loading branch information
ddusichka committed Sep 28, 2023
1 parent 5e9a815 commit 2f75840
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 1 deletion.
14 changes: 14 additions & 0 deletions migrations/1695922686467-add date to user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class addDateToUser1695922686467 implements MigrationInterface {
name = 'addDateToUser1695922686467'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" ADD "createdDate" TIMESTAMP NOT NULL DEFAULT now()`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "createdDate"`);
}

}
1 change: 1 addition & 0 deletions src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockUser: User = {
firstName: 'first',
lastName: 'last',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

const serviceMock: Partial<AuthService> = {
Expand Down
1 change: 1 addition & 0 deletions src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const mockUser: User = {
firstName: 'first',
lastName: 'last',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-28'),
};

const mockCognitoService = {
Expand Down
1 change: 1 addition & 0 deletions src/auth/guards/roles.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockUser = (role: Role): User => ({
firstName: 'first',
lastName: 'last',
role,
createdDate: new Date('2023-09-28'),
});

const mockContext = (user?: User): Partial<ExecutionContext> => ({
Expand Down
1 change: 1 addition & 0 deletions src/auth/middleware/authentication.middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const mockUser: User = {
firstName: 'first',
lastName: 'last',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

const mockAuthService: Partial<AuthService> = {
Expand Down
5 changes: 4 additions & 1 deletion src/user/types/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsEmail } from 'class-validator';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
import { Role } from './role';

@Entity()
Expand All @@ -25,4 +25,7 @@ export class User {
default: Role.ADMIN,
})
role: Role;

@CreateDateColumn()
createdDate: Date;
}
3 changes: 3 additions & 0 deletions src/user/types/user.examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const ADMIN_1: User = {
lastName: 'last',
email: 'test@test.com',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

export const ADMIN_2: User = {
Expand All @@ -15,6 +16,7 @@ export const ADMIN_2: User = {
lastName: 'last',
email: 'already@exists.com',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

export const RESEARCHER_1: User = {
Expand All @@ -23,4 +25,5 @@ export const RESEARCHER_1: User = {
lastName: 'last',
email: 'researcher@test.com',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-24'),
};
1 change: 1 addition & 0 deletions src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockUser: User = {
firstName: 'test',
lastName: 'user',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

const listMockUsers: User[] = [mockUser];
Expand Down
2 changes: 2 additions & 0 deletions src/user/user.examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export const userExamples = [
role: Role.ADMIN,
firstName: 'admin',
lastName: 'user',
createdDate: new Date('2023-09-24'),
},
{
email: 'c4cneu.jpal+researcher@gmail.com',
role: Role.RESEARCHER,
firstName: 'researcher',
lastName: 'user',
createdDate: new Date('2023-09-24'),
},
];
2 changes: 2 additions & 0 deletions src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const mockUser: User = {
firstName: 'William',
lastName: 'user',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

export const mockResearcher: User = {
Expand All @@ -22,6 +23,7 @@ export const mockResearcher: User = {
firstName: 'Paige',
lastName: 'Turner',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-24'),
};

const listMockUsers: User[] = [mockUser, mockResearcher];
Expand Down

0 comments on commit 2f75840

Please sign in to comment.