src/*/actionlog*.ts: implemented queries for action log
parent
98437cc33a
commit
97ee273ae4
@ -0,0 +1,28 @@
|
||||
import { DataSource } from 'apollo-datasource';
|
||||
import { Connection, getConnection } from 'typeorm';
|
||||
import { ActionLog } from '../../model/ActionLog';
|
||||
|
||||
export class ActionLogAPI extends DataSource {
|
||||
connection : Connection
|
||||
constructor () {
|
||||
super();
|
||||
this.connection = getConnection();
|
||||
}
|
||||
|
||||
async actionLogByUserId (userId: number) {
|
||||
return await this.connection.getRepository(ActionLog)
|
||||
.createQueryBuilder('al')
|
||||
.select()
|
||||
.where('"userId" = :uid', { uid: userId })
|
||||
.orderBy('date', 'DESC')
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async actionLogAll () {
|
||||
return await this.connection.getRepository(ActionLog)
|
||||
.createQueryBuilder('al')
|
||||
.select()
|
||||
.orderBy('date', 'DESC')
|
||||
.getMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import { Permission } from '../datasources/userserver/permission';
|
||||
import { GraphQLError } from 'graphql';
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
actionLog: (_: any, __:any, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||
if (req.permissions.includes(Permission.ReadActionLog)) {
|
||||
return dataSources.actionLogAPI.actionLogByUserId(req.userId);
|
||||
} else {
|
||||
return new GraphQLError('Insufficient Permissions');
|
||||
}
|
||||
},
|
||||
actionLogByUser: (_: any, { id }: {id: number}, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||
if (req.permissions.includes(Permission.ReadActionLogAll)) {
|
||||
return dataSources.actionLogAPI.actionLogByUserId(id);
|
||||
} else {
|
||||
return new GraphQLError('Insufficient Permissions');
|
||||
}
|
||||
},
|
||||
actionLogAll: (_: any, __: any, { dataSources, req }:{dataSources: any, req: any }) => {
|
||||
if (req.permissions.includes(Permission.ReadActionLogAll)) {
|
||||
return dataSources.actionLogAPI.actionLogAll();
|
||||
} else {
|
||||
return new GraphQLError('Insufficient Permissions');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue