deletee method
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Post, Body, Param, Header } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, Header, Delete } from '@nestjs/common';
|
||||
import {StoreService} from './store.service';
|
||||
import {Store, StoreResponse, StoreRequest} from './store.schema';
|
||||
import {ApiResponse} from '@nestjs/swagger';
|
||||
@ -21,7 +21,7 @@ export class StoreController {
|
||||
return this.storeService.findAll();
|
||||
}
|
||||
|
||||
@Get(':key?')
|
||||
@Get(':key')
|
||||
@Header(...ALLOW_ORIGIN_ALL)
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
@ -42,4 +42,15 @@ export class StoreController {
|
||||
async create(@Body() createStoreClass: StoreRequest): Promise<Store> {
|
||||
return this.storeService.create(createStoreClass);
|
||||
}
|
||||
|
||||
@Delete(':key')
|
||||
@Header(...ALLOW_ORIGIN_ALL)
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Удаляет пару ключ-значение по ключу',
|
||||
type: String,
|
||||
})
|
||||
async removeOne(@Param() {key}: {key: string}): Promise<string> {
|
||||
return this.storeService.removeOne(key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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}`);
|
||||
}
|
||||
}
|
||||
@ -16,3 +16,7 @@ content-type: application/json
|
||||
"age": 15
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
DELETE http://localhost:4001/store/testApi HTTP/1.1
|
||||
Reference in New Issue
Block a user