mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
Add Admin module and entity
This commit is contained in:
34
backend/src/modules/admin/admin.service.ts
Normal file
34
backend/src/modules/admin/admin.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Admin } from 'libs/database/admin.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AdminService {
|
||||
private readonly logger: Logger = new Logger(AdminService.name);
|
||||
constructor(@InjectRepository(Admin) private adminRepository: Repository<Admin>) {}
|
||||
|
||||
async getAdmins() {
|
||||
try {
|
||||
this.logger.debug(`[admin.getAdmins]`);
|
||||
const admins = await this.adminRepository.find();
|
||||
return admins;
|
||||
} catch (error) {
|
||||
this.logger.log(`[getAdmin] ${JSON.stringify({ error })}`);
|
||||
}
|
||||
}
|
||||
async checkIsAdmin(id: string) {
|
||||
try {
|
||||
this.logger.debug(`[admin.checkIsAdmin]`);
|
||||
const admins = await this.adminRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!admins) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
this.logger.log(`[checkIsAdmin] ${JSON.stringify({ error })}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user