Skip to content

Commit

Permalink
Feature: Add example user pg repository
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Hoplin committed Jul 10, 2024
1 parent 8a71491 commit 9a8579f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/modules/users/users.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { JwtStrategy } from './guards/strategy';
import { User, UserSchema } from '@src/infrastructure';
import { UsersRepository } from './users.repository';
import { AuthModule } from '../auth/auth.module';
import { UsersPGRepository } from './users.pg.repository';

@Module({
imports: [
AuthModule,
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
],
controllers: [UsersController],
providers: [UsersService, UsersRepository, JwtStrategy],
providers: [UsersService, UsersRepository, UsersPGRepository, JwtStrategy],
})
export class UsersModule {}
30 changes: 30 additions & 0 deletions src/modules/users/users.pg.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';

// TODO: Service class name will be changed after the naming convention is discussed later.
@Injectable()
export class UsersPGRepository {
constructor(private readonly prisma: PrismaService) {}
private defaultFolderName = '나중에 읽을 링크';

async findOrCreate(deviceToken: string) {
const user = await this.prisma.user.upsert({
where: {
deviceToken: deviceToken,
},
create: {
deviceToken: deviceToken,
folders: {
create: [
{
name: this.defaultFolderName,
type: 'default',
},
],
},
},
update: {},
});
return user;
}
}

0 comments on commit 9a8579f

Please sign in to comment.