deletee method

This commit is contained in:
vigdorov
2020-07-03 21:50:30 +03:00
parent 6ca9059dc4
commit 7a56b148f5
3 changed files with 30 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import {Model} from 'mongoose';
import {Injectable} from '@nestjs/common';
import {Injectable, NotFoundException} from '@nestjs/common';
import {InjectModel} from '@nestjs/mongoose';
import {Store, StoreRequest} from './store.schema';
@ -26,4 +26,15 @@ export class StoreService {
async findOne(key: string): Promise<Store> {
return this.storeModel.findOne({key});
}
async removeOne(key: string): Promise<string> {
const searchStore = await this.findOne(key);
if (searchStore) {
await searchStore.remove();
return 'ok';
}
throw new NotFoundException(`Not Found key - ${key}`);
}
}