src/model/actionlogs.ts: added actions e.g. update, delete

pull/14/head
leonnicolas 4 years ago
parent 97ee273ae4
commit 660e775de2
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -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<any>, alias: string, updates: any, userId: number) {
static async log (em: EntityManager, target: ObjectType<any>, 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)
};

@ -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;

@ -869,6 +869,7 @@ type ActionLog {
id: ID!
userId: ID!
date: Date!
action: String!
entity: String!
"in json format"
entriesOld: String!

Loading…
Cancel
Save