create admins endpoint

This commit is contained in:
Errormacr
2023-11-18 20:41:14 +03:00
parent 6bf6886826
commit 5c0b94e09e
59 changed files with 704 additions and 3 deletions

View 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]`);
let 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]`);
let admins = await this.adminRepository.findOne({
where: { id: id },
});
if (!admins) {
return false
}
return true;
} catch (error) {
this.logger.log(`[checkIsAdmin] ${JSON.stringify({ error })}`);
}
}
}