Skip to content

Commit

Permalink
Update created_at and updated_at columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kumuditha-udayanga committed Aug 11, 2023
1 parent 969595a commit ff80da0
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 27 deletions.
27 changes: 26 additions & 1 deletion src/entity/category.entity.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
import {
BeforeInsert,
BeforeUpdate,
Column,
Entity,
PrimaryGeneratedColumn
} from "typeorm";
import {v4 as uuidv4} from 'uuid';

@Entity("category")
class Category {
@PrimaryGeneratedColumn('uuid')
id!: bigint
uuid!: string

@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
created_at: Date | undefined;

@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
updated_at: Date | undefined;

@Column({type: 'varchar', length: 255})
category: string


constructor(
category: string,
) {
this.category = category;
}

@BeforeInsert()
@BeforeUpdate()
updateTimestamps() {

Check failure on line 33 in src/entity/category.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
this.updated_at = new Date();
if (!this.uuid) {
this.created_at = new Date();
}
}
@BeforeInsert()

Check failure on line 39 in src/entity/category.entity.ts

View workflow job for this annotation

GitHub Actions / build

Expected blank line between class members
async generateUuid() {

Check failure on line 40 in src/entity/category.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
if (!this.uuid) {
this.uuid = uuidv4();
}
}
}

export default Category;
30 changes: 26 additions & 4 deletions src/entity/email.entity.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {
BeforeInsert,
BeforeUpdate,
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn
} from "typeorm";
import {EmailStatusTypes} from "../enums/enums";
import {v4 as uuidv4} from 'uuid';


@Entity("email")
class Email {
@PrimaryGeneratedColumn('uuid')
id!: bigint
uuid!: string

@Column({type: 'varchar', length: 255})
recipient: string
Expand All @@ -23,8 +26,11 @@ class Email {
@Column({type: 'enum', enum: EmailStatusTypes})
state: EmailStatusTypes

@CreateDateColumn()
created_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
created_at: Date | undefined;

@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
updated_at: Date | undefined;

constructor(
recipient: string,
Expand All @@ -37,6 +43,22 @@ class Email {
this.content = content;
this.state = state;
}

@BeforeInsert()
@BeforeUpdate()
updateTimestamps() {

Check failure on line 49 in src/entity/email.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
this.updated_at = new Date();
if (!this.uuid) {
this.created_at = new Date();
}
}

@BeforeInsert()
async generateUuid() {

Check failure on line 57 in src/entity/email.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
if (!this.uuid) {
this.uuid = uuidv4();
}
}
}

export default Email;
33 changes: 25 additions & 8 deletions src/entity/mentee.entity.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import {
BeforeInsert,
BeforeUpdate,
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
UpdateDateColumn
PrimaryGeneratedColumn
} from "typeorm";
import {MenteeApplication} from "../types";
import Mentor from "./mentor.entity";
import profileEntity from "./profile.entity";
import {MenteeStateTypes} from "../enums/enums";
import {v4 as uuidv4} from "uuid";

@Entity('mentee')
class Mentee {
@PrimaryGeneratedColumn()
id!: bigint
uuid!: string

@Column({type:"enum"})
state: MenteeStateTypes
Expand All @@ -37,11 +38,11 @@ class Mentee {
@ManyToOne(() => Mentor, mentor => mentor.mentees)
mentor: Mentor

@CreateDateColumn()
created_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
created_at: Date | undefined;

@UpdateDateColumn()
updated_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
updated_at: Date | undefined;

constructor(
state: MenteeStateTypes,
Expand All @@ -58,6 +59,22 @@ class Mentee {
this.profile = profile;
this.mentor = mentor;
}

@BeforeInsert()
@BeforeUpdate()
updateTimestamps() {

Check failure on line 65 in src/entity/mentee.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
this.updated_at = new Date();
if (!this.uuid) {
this.created_at = new Date();
}
}

@BeforeInsert()
async generateUuid() {

Check failure on line 73 in src/entity/mentee.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
if (!this.uuid) {
this.uuid = uuidv4();
}
}
}

export default Mentee;
32 changes: 24 additions & 8 deletions src/entity/mentor.entity.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {
BeforeInsert, BeforeUpdate,
Column,
CreateDateColumn,
Entity,
JoinColumn,
OneToMany,
OneToOne,
PrimaryGeneratedColumn,
UpdateDateColumn
PrimaryGeneratedColumn
} from "typeorm";
import profileEntity from "./profile.entity";
import Mentee from "./mentee.entity";
import Category from "./category.entity";
import {v4 as uuidv4} from "uuid";

@Entity("mentor")
class Mentor {
@PrimaryGeneratedColumn('uuid')
id!: bigint
uuid!: string

@Column({type: 'varchar', length: 255})
state: string
Expand All @@ -36,11 +36,11 @@ class Mentor {
@OneToMany(() => Mentee, mentee => mentee.mentor)
mentees: Mentee[];

@CreateDateColumn()
created_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
created_at: Date | undefined;

@UpdateDateColumn()
updated_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
updated_at: Date | undefined;

constructor(
state: string,
Expand All @@ -57,6 +57,22 @@ class Mentor {
this.profile = profile;
this.mentees =mentees;
}

@BeforeInsert()
@BeforeUpdate()
updateTimestamps() {

Check failure on line 63 in src/entity/mentor.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
this.updated_at = new Date();
if (!this.uuid) {
this.created_at = new Date();
}
}

@BeforeInsert()
async generateUuid() {

Check failure on line 71 in src/entity/mentor.entity.ts

View workflow job for this annotation

GitHub Actions / build

Missing return type on function
if (!this.uuid) {
this.uuid = uuidv4();
}
}
}

export default Mentor;
29 changes: 23 additions & 6 deletions src/entity/platform.entity.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {
BeforeInsert, BeforeUpdate,
Column,
CreateDateColumn,

Check failure on line 4 in src/entity/platform.entity.ts

View workflow job for this annotation

GitHub Actions / build

'CreateDateColumn' is defined but never used

Check warning on line 4 in src/entity/platform.entity.ts

View workflow job for this annotation

GitHub Actions / build

'CreateDateColumn' is defined but never used
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn

Check warning on line 7 in src/entity/platform.entity.ts

View workflow job for this annotation

GitHub Actions / build

'UpdateDateColumn' is defined but never used
} from "typeorm";
import {v4 as uuidv4} from "uuid";

@Entity("platform")
class Platform {
@PrimaryGeneratedColumn('uuid')
id!: bigint
uuid!: string

@Column()
description: string
Expand All @@ -29,11 +31,11 @@ class Platform {
@Column({type: 'varchar', length: 255})
title: string

@CreateDateColumn()
created_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
created_at: Date | undefined;

@UpdateDateColumn()
updated_at: Date | undefined
@Column({type: 'timestamp', default:() => 'CURRENT_TIMESTAMP' })
updated_at: Date | undefined;

constructor(
description: string,
Expand All @@ -42,7 +44,6 @@ class Platform {
landing_page_url: string,
email_templates: JSON,
title: string,
category: string,
) {
this.description = description;
this.mentor_questions = mentor_questions;
Expand All @@ -51,6 +52,22 @@ class Platform {
this.email_templates = email_templates;
this.title = title;
}

@BeforeInsert()
@BeforeUpdate()
updateTimestamps() {
this.updated_at = new Date();
if (!this.uuid) {
this.created_at = new Date();
}
}

@BeforeInsert()
async generateUuid() {
if (!this.uuid) {
this.uuid = uuidv4();
}
}
}

export default Platform;
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface Option {
// todo: To be determined
}

interface Question {
question: string
answer: string
Expand Down

0 comments on commit ff80da0

Please sign in to comment.