Skip to content

Commit

Permalink
Merge pull request #984 from kir-dev/feature/nullable_email
Browse files Browse the repository at this point in the history
make email nullable in user schema
  • Loading branch information
Tschonti committed May 10, 2024
2 parents 31eef7b + 0db1332 commit d613dcf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"typescript.referencesCodeLens.enabled": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"files.insertFinalNewline": true,
"eslint.enable": true
Expand Down
16 changes: 16 additions & 0 deletions migrations/20240510212804_nullable_email.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.alterTable('users', table => {
table.string('email').nullable().alter()
})
}


export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable('users', table => {
table.string('email').notNullable().alter()
})
}

5 changes: 4 additions & 1 deletion src/components/tickets/ticket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const sendEmailToTicketAdmins = asyncWrapper(
async (req: Request, res: Response, next: NextFunction) => {
const ticket = req.body

const emailRecepients = await User.query().where({ role: RoleType.TICKET_ADMIN })
const emailRecepients = await User
.query()
.where({ role: RoleType.TICKET_ADMIN })
.whereNotNull('email')
sendEmail(emailRecepients, {
subject: `Új hibajegyet vettek fel a ${ticket.roomNumber}. emeleti tanulószobába!`,
body: `Új hibajegyet vettek fel a ${ticket.roomNumber}. emeleti tanulószobába!
Expand Down
2 changes: 1 addition & 1 deletion src/components/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { asyncWrapper } from '../../util/asyncWrapper'
interface OAuthUser {
displayName: string
internal_id: string
mail: string
mail?: string
}

export const getUser = asyncWrapper(async (req: Request, res: Response, next: NextFunction) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum RoleType {
export class User extends Model {
id!: number
name: string
email: string
email?: string
authSchId: string
role: RoleType
floor: number
Expand Down Expand Up @@ -45,7 +45,7 @@ export class User extends Model {
static get jsonSchema(): Record<string, any> {
return {
type: 'object',
required: ['name', 'email', 'authSchId'],
required: ['name', 'authSchId'],

properties: {
id: { type: 'integer' },
Expand Down

0 comments on commit d613dcf

Please sign in to comment.