-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create tip api uses TipRepository
- Loading branch information
1 parent
3cc88c6
commit ad2f584
Showing
2 changed files
with
37 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,28 @@ | ||
import { Action } from './interface' | ||
import { OneApiFunc } from '@/api/one/types' | ||
import Time from '@/modules/time' | ||
import { TipRepository } from '@/database/repository/tip-repository' | ||
import { oneApiResponse } from '@/api/one/utils' | ||
import prisma from '@/modules/prisma' | ||
|
||
const func: OneApiFunc<Action> = async (data) => { | ||
const { authPayload, title, topic, body } = data | ||
const { userId } = authPayload | ||
|
||
const currentTime = Time.getIsoString() | ||
const user = await prisma.user.findOne({ | ||
where: { | ||
id: userId, | ||
}, | ||
}) | ||
|
||
const tip = await prisma.tip.create({ | ||
data: { | ||
user: { | ||
connect: { | ||
id: userId, | ||
}, | ||
}, | ||
title, | ||
topic, | ||
body, | ||
randomNickname: user.randomNickname, | ||
createdAt: currentTime, | ||
editedAt: currentTime, | ||
}, | ||
}) | ||
const tipId = await TipRepository.create( | ||
userId, | ||
title, | ||
topic, | ||
body, | ||
user.randomNickname | ||
) | ||
|
||
return oneApiResponse<Action>({ tipId: tip.id }) | ||
return oneApiResponse<Action>({ tipId }) | ||
} | ||
|
||
export default func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters