Skip to content

Commit

Permalink
feat: 사용자 이름이 제공되지 않았을 경우 기본갑 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyongp committed Nov 15, 2023
1 parent 202b31c commit eb64793
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Prisma } from "@prisma/client";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
import { prisma } from "prisma";
import { HttpError } from "utils/http";
import { CursorBasedPagination } from "utils/pagination";

// TODO: AuthUser Context 전달하도록 개선
export const userInclude = (authUserId: number): Prisma.UserInclude => ({
Expand Down Expand Up @@ -131,15 +130,22 @@ export async function findByProvider(provider: string, providerId: string) {
});
}

export function create(input: {
export async function create(input: {
username?: string | null;
avatarUrl?: string | null;
provider: string;
providerId: string;
}) {
return prisma.user.create({
data: { ...input },
const user = await prisma.user.create({
data: input,
});
if (!user.username) {
await prisma.user.update({
where: { id: user.id },
data: { username: `user-${user.id}` },
});
}
return user;
}

export function update(
Expand Down

0 comments on commit eb64793

Please sign in to comment.