Skip to content

Commit

Permalink
Create column group.kind
Browse files Browse the repository at this point in the history
  • Loading branch information
tomitheninja committed Aug 25, 2021
1 parent 9d26d2b commit b931f77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions migrations/20210825151547_add_group_kind_to_groups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as Knex from 'knex'

export async function up(knex: Knex): Promise<void> {
return knex.schema.table('groups', table => {
table.enu('kind', ['classic', 'anonymous'], {
useNative: true,
enumName: 'group_kind'
}).defaultTo('classic')
})
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.table('groups', table => {
table.dropColumn('kind')
})
}
10 changes: 9 additions & 1 deletion src/components/groups/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Model } from 'objection'

import { User } from '../users/user'

export enum GroupKind {
classic = 'classic',
anonymous = 'anonymous'
}

export class Group extends Model {
id!: number
name: string
Expand All @@ -18,6 +23,8 @@ export class Group extends Model {
createdAt: Date
maxAttendees: number

kind = GroupKind.classic

$beforeInsert(): void {
this.createdAt = new Date()
}
Expand Down Expand Up @@ -63,7 +70,8 @@ export class Group extends Model {
place: { type: 'string' },
startDate: { type: 'datetime' },
endDate: { type: 'datetime' },
maxAttendees: { type: 'integer' }
maxAttendees: { type: 'integer' },
kind: { type: 'string' }
}
}
}
Expand Down

0 comments on commit b931f77

Please sign in to comment.