46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
|
import { Injectable } from '@nestjs/common';
|
||
|
import { BaseService } from '../base/base.service';
|
||
|
import { db, ObjectType, Prisma, UserProfile } from '@nice/common';
|
||
|
import EventBus, { CrudOperation } from '@server/utils/event-bus';
|
||
|
import { DefaultArgs } from '@prisma/client/runtime/library';
|
||
|
|
||
|
@Injectable()
|
||
|
export class ReaderService extends BaseService<Prisma.ReaderDelegate> {
|
||
|
constructor() {
|
||
|
super(db, ObjectType.READER, false);
|
||
|
}
|
||
|
async create(args: Prisma.ReaderCreateArgs) {
|
||
|
const result = await super.create(args);
|
||
|
this.emitDataChanged(CrudOperation.CREATED, result);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
async update(args: Prisma.ReaderUpdateArgs) {
|
||
|
const result = await super.update(args);
|
||
|
this.emitDataChanged(CrudOperation.UPDATED, result);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
async findMany(args: Prisma.ReaderFindManyArgs) {
|
||
|
const result = await super.findMany(args);
|
||
|
return result;
|
||
|
}
|
||
|
async findFirst(args: Prisma.ReaderFindFirstArgs) {
|
||
|
const result = await super.findFirst(args);
|
||
|
return result;
|
||
|
}
|
||
|
async softDeleteByIds(ids: string[]) {
|
||
|
const result = await super.softDeleteByIds(ids);
|
||
|
this.emitDataChanged(CrudOperation.DELETED, result);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
private emitDataChanged(operation: CrudOperation, data: any) {
|
||
|
EventBus.emit('dataChanged', {
|
||
|
type: ObjectType.READER,
|
||
|
operation,
|
||
|
data,
|
||
|
});
|
||
|
}
|
||
|
}
|