diff --git a/src/datasources/db/utils.ts b/src/datasources/db/utils.ts index d402930..c8da655 100644 --- a/src/datasources/db/utils.ts +++ b/src/datasources/db/utils.ts @@ -1,7 +1,7 @@ import { Connection, EntityManager, ObjectType } from 'typeorm'; import { Lockable } from '../../model/CargoBike'; import { GraphQLError } from 'graphql'; -import { ActionLog } from '../../model/ActionLog'; +import { ActionLog, Actions } from '../../model/ActionLog'; export function genDateRange (struct: any) { if (struct.to === undefined) { @@ -170,7 +170,7 @@ export class ActionLogger { return ret; } - static async log (em: EntityManager, target: ObjectType, alias: string, updates: any, userId: number) { + static async log (em: EntityManager, target: ObjectType, alias: string, updates: any, userId: number, action: Actions = Actions.UPDATE) { const oldValues = await em.getRepository(target).createQueryBuilder(alias) .select(this.buildSelect(updates, alias)) .where('id = :id', { id: updates.id }) @@ -201,6 +201,7 @@ export class ActionLogger { const logEntry : ActionLog = { userId: userId, entity: target.name, + action: action, entriesOld: JSON.stringify(oldValues), entriesNew: JSON.stringify(updates) }; diff --git a/src/model/ActionLog.ts b/src/model/ActionLog.ts index c502678..76abbc9 100644 --- a/src/model/ActionLog.ts +++ b/src/model/ActionLog.ts @@ -1,5 +1,13 @@ +/* eslint no-unused-vars: "off" */ import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'; +export enum Actions { + UPDATE='UPDATE', + SOFT_DELETE='SOFT_DELETE', + DELETE='DELETE', + RESTORE='RESTORE', +} + @Entity() export class ActionLog { @PrimaryGeneratedColumn() @@ -8,6 +16,9 @@ export class ActionLog { @CreateDateColumn() date?: Date; + @Column() + action: string; + @Column() userId: number; diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index d2e153e..63f30ef 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -869,6 +869,7 @@ type ActionLog { id: ID! userId: ID! date: Date! + action: String! entity: String! "in json format" entriesOld: String!