-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Temporary pg repository, prisma annotate
- Loading branch information
Showing
4 changed files
with
159 additions
and
159 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,79 +1,79 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { FolderType } from '@prisma/client'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
import { F002 } from './error'; | ||
// import { Injectable, NotFoundException } from '@nestjs/common'; | ||
// import { FolderType } from '@prisma/client'; | ||
// import { PrismaService } from '../prisma/prisma.service'; | ||
// import { F002 } from './error'; | ||
|
||
// TODO: Service class name will be changed after the naming convention is discussed later. | ||
@Injectable() | ||
export class FoldersPGRepository { | ||
constructor(private readonly prisma: PrismaService) {} | ||
// // TODO: Service class name will be changed after the naming convention is discussed later. | ||
// @Injectable() | ||
// export class FoldersPGRepository { | ||
// constructor(private readonly prisma: PrismaService) {} | ||
|
||
async create(userId: string, name: string, type: FolderType) { | ||
const folder = await this.prisma.folder.create({ | ||
data: { | ||
userId, | ||
name, | ||
type, | ||
}, | ||
}); | ||
// async create(userId: string, name: string, type: FolderType) { | ||
// const folder = await this.prisma.folder.create({ | ||
// data: { | ||
// userId, | ||
// name, | ||
// type, | ||
// }, | ||
// }); | ||
|
||
return folder; | ||
} | ||
// return folder; | ||
// } | ||
|
||
async createMany( | ||
folders: { userId: string; name: string; type: FolderType }[], | ||
) { | ||
const createdFolders = await this.prisma.folder.createMany({ | ||
data: folders, | ||
}); | ||
return createdFolders; | ||
} | ||
// async createMany( | ||
// folders: { userId: string; name: string; type: FolderType }[], | ||
// ) { | ||
// const createdFolders = await this.prisma.folder.createMany({ | ||
// data: folders, | ||
// }); | ||
// return createdFolders; | ||
// } | ||
|
||
async findByUserId(userId: string) { | ||
const folders = await this.prisma.folder.findMany({ | ||
where: { userId }, | ||
}); | ||
return folders; | ||
} | ||
// async findByUserId(userId: string) { | ||
// const folders = await this.prisma.folder.findMany({ | ||
// where: { userId }, | ||
// }); | ||
// return folders; | ||
// } | ||
|
||
async checkUserHasFolder(userId: string, name: string) { | ||
const checkFolder = await this.prisma.folder.findFirst({ | ||
where: { | ||
userId: userId, | ||
name: name, | ||
}, | ||
}); | ||
return checkFolder ? true : false; | ||
} | ||
// async checkUserHasFolder(userId: string, name: string) { | ||
// const checkFolder = await this.prisma.folder.findFirst({ | ||
// where: { | ||
// userId: userId, | ||
// name: name, | ||
// }, | ||
// }); | ||
// return checkFolder ? true : false; | ||
// } | ||
|
||
async findOneOrFail(param: { userId: string; name: string }) { | ||
const folder = await this.prisma.folder.findFirst({ | ||
where: param, | ||
}); | ||
if (!folder) { | ||
throw new NotFoundException(F002); | ||
} | ||
// async findOneOrFail(param: { userId: string; name: string }) { | ||
// const folder = await this.prisma.folder.findFirst({ | ||
// where: param, | ||
// }); | ||
// if (!folder) { | ||
// throw new NotFoundException(F002); | ||
// } | ||
|
||
return folder; | ||
} | ||
// return folder; | ||
// } | ||
|
||
async deleteAllCustomFolder(userId: string) { | ||
await this.prisma.folder.deleteMany({ | ||
where: { | ||
userId, | ||
type: FolderType.custom, | ||
}, | ||
}); | ||
} | ||
// async deleteAllCustomFolder(userId: string) { | ||
// await this.prisma.folder.deleteMany({ | ||
// where: { | ||
// userId, | ||
// type: FolderType.custom, | ||
// }, | ||
// }); | ||
// } | ||
|
||
async getDefaultFolder(userId: string) { | ||
const folder = await this.prisma.folder.findFirst({ | ||
where: { | ||
userId, | ||
type: FolderType.default, | ||
}, | ||
}); | ||
// async getDefaultFolder(userId: string) { | ||
// const folder = await this.prisma.folder.findFirst({ | ||
// where: { | ||
// userId, | ||
// type: FolderType.default, | ||
// }, | ||
// }); | ||
|
||
return folder; | ||
} | ||
} | ||
// return folder; | ||
// } | ||
// } |
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,9 +1,9 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import { PrismaService } from './prisma.service'; | ||
// import { Global, Module } from '@nestjs/common'; | ||
// import { PrismaService } from './prisma.service'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [PrismaService], | ||
exports: [PrismaService], | ||
}) | ||
export class PrismaModule {} | ||
// @Global() | ||
// @Module({ | ||
// providers: [PrismaService], | ||
// exports: [PrismaService], | ||
// }) | ||
// export class PrismaModule {} |
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,59 +1,59 @@ | ||
import { | ||
Injectable, | ||
Logger, | ||
OnModuleDestroy, | ||
OnModuleInit, | ||
} from '@nestjs/common'; | ||
import { Prisma, PrismaClient } from '@prisma/client'; | ||
// import { | ||
// Injectable, | ||
// Logger, | ||
// OnModuleDestroy, | ||
// OnModuleInit, | ||
// } from '@nestjs/common'; | ||
// import { Prisma, PrismaClient } from '@prisma/client'; | ||
|
||
@Injectable() | ||
export class PrismaService | ||
extends PrismaClient<Prisma.PrismaClientOptions, Prisma.LogLevel> | ||
implements OnModuleInit, OnModuleDestroy | ||
{ | ||
private context = 'Prisma-Debug'; | ||
private logger = new Logger(this.context); | ||
// @Injectable() | ||
// export class PrismaService | ||
// extends PrismaClient<Prisma.PrismaClientOptions, Prisma.LogLevel> | ||
// implements OnModuleInit, OnModuleDestroy | ||
// { | ||
// private context = 'Prisma-Debug'; | ||
// private logger = new Logger(this.context); | ||
|
||
// Prisma Logging Reference: https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/logging#event-based-logging | ||
constructor() { | ||
super({ | ||
log: [ | ||
{ | ||
emit: 'event', | ||
level: 'query', | ||
}, | ||
{ | ||
emit: 'event', | ||
level: 'error', | ||
}, | ||
{ | ||
emit: 'event', | ||
level: 'warn', | ||
}, | ||
], | ||
}); | ||
} | ||
// // Prisma Logging Reference: https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/logging#event-based-logging | ||
// constructor() { | ||
// super({ | ||
// log: [ | ||
// { | ||
// emit: 'event', | ||
// level: 'query', | ||
// }, | ||
// { | ||
// emit: 'event', | ||
// level: 'error', | ||
// }, | ||
// { | ||
// emit: 'event', | ||
// level: 'warn', | ||
// }, | ||
// ], | ||
// }); | ||
// } | ||
|
||
async onModuleDestroy() { | ||
await this.$disconnect(); | ||
} | ||
// async onModuleDestroy() { | ||
// await this.$disconnect(); | ||
// } | ||
|
||
async onModuleInit() { | ||
// Prisma Raw Query logging Config | ||
Object.assign( | ||
this, | ||
this.$on('query', (event) => { | ||
this.logger.debug( | ||
`Query - [${event.timestamp}] - ${event.query}, Duration - ${event.duration}ms`, | ||
); | ||
}), | ||
this.$on('error', (event) => { | ||
this.logger.error(`Error - [${event.timestamp}] - ${event.message}`); | ||
}), | ||
this.$on('warn', (event) => { | ||
this.logger.warn(`Warn - [${event.timestamp}] - ${event.message}`); | ||
}), | ||
); | ||
await this.$connect(); | ||
} | ||
} | ||
// async onModuleInit() { | ||
// // Prisma Raw Query logging Config | ||
// Object.assign( | ||
// this, | ||
// this.$on('query', (event) => { | ||
// this.logger.debug( | ||
// `Query - [${event.timestamp}] - ${event.query}, Duration - ${event.duration}ms`, | ||
// ); | ||
// }), | ||
// this.$on('error', (event) => { | ||
// this.logger.error(`Error - [${event.timestamp}] - ${event.message}`); | ||
// }), | ||
// this.$on('warn', (event) => { | ||
// this.logger.warn(`Warn - [${event.timestamp}] - ${event.message}`); | ||
// }), | ||
// ); | ||
// await this.$connect(); | ||
// } | ||
// } |
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,30 +1,30 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
// 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 = '나중에 읽을 링크'; | ||
// // 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; | ||
} | ||
} | ||
// 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; | ||
// } | ||
// } |