Skip to content

Commit

Permalink
refactor: add delete method in Tip class
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-garden committed Jun 18, 2020
1 parent ad2f584 commit 8dcdc12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/api/one/scheme/tip/delete-tip.action/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ const func: OneApiFunc<Action> = async (data) => {
return oneApiResponse<Action>(OneApiError.FORBIDDEN)
}

await prisma.tip.update({
where: { id: tipId },
data: { isRemoved: true },
})

Tip.delete(tipId)
return oneApiResponse<Action>({ isRemoved: true })
}

Expand Down
8 changes: 8 additions & 0 deletions src/database/models/tip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ export class Tip extends Model {
})
return true
}

static async delete(tipId: number): Promise<boolean> {
await prisma.tip.update({
where: { id: tipId },
data: { isRemoved: true },
})
return true
}
}

export const getTip = createInitModelFunction(Tip, 'tip', {
Expand Down
3 changes: 1 addition & 2 deletions src/database/repository/tip-repository.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down

0 comments on commit 8dcdc12

Please sign in to comment.