From 8dcdc12d333f7ec26f0a49736d4b0b424007757c Mon Sep 17 00:00:00 2001 From: GardenLee Date: Fri, 19 Jun 2020 00:33:15 +0900 Subject: [PATCH] refactor: add delete method in Tip class --- src/api/one/scheme/tip/delete-tip.action/function.ts | 6 +----- src/database/models/tip.ts | 8 ++++++++ src/database/repository/tip-repository.ts | 3 +-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/api/one/scheme/tip/delete-tip.action/function.ts b/src/api/one/scheme/tip/delete-tip.action/function.ts index cb147b4d..bdfb4e95 100644 --- a/src/api/one/scheme/tip/delete-tip.action/function.ts +++ b/src/api/one/scheme/tip/delete-tip.action/function.ts @@ -20,11 +20,7 @@ const func: OneApiFunc = async (data) => { return oneApiResponse(OneApiError.FORBIDDEN) } - await prisma.tip.update({ - where: { id: tipId }, - data: { isRemoved: true }, - }) - + Tip.delete(tipId) return oneApiResponse({ isRemoved: true }) } diff --git a/src/database/models/tip.ts b/src/database/models/tip.ts index 5d7cefa3..5b7fc85a 100644 --- a/src/database/models/tip.ts +++ b/src/database/models/tip.ts @@ -159,6 +159,14 @@ export class Tip extends Model { }) return true } + + static async delete(tipId: number): Promise { + await prisma.tip.update({ + where: { id: tipId }, + data: { isRemoved: true }, + }) + return true + } } export const getTip = createInitModelFunction(Tip, 'tip', { diff --git a/src/database/repository/tip-repository.ts b/src/database/repository/tip-repository.ts index 266a1f44..62ecf44f 100644 --- a/src/database/repository/tip-repository.ts +++ b/src/database/repository/tip-repository.ts @@ -1,6 +1,5 @@ -import { Tip, TipAttrs } from '../models/tip' - import Time from '@/modules/time' +import { TipAttrs } from '../models/tip' import { TipTopic } from '@prisma/client' import prisma from '@/modules/prisma'