-
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.
chore: refactor structure for repository and service pattern properly
- Loading branch information
Showing
21 changed files
with
194 additions
and
182 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
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
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
This file was deleted.
Oops, something went wrong.
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,7 +1,6 @@ | ||
/* @org/backend/decorators */ | ||
export * from "@org/backend/decorators/@Autowired"; | ||
export * from "@org/backend/decorators/@Injectable"; | ||
export * from "@org/backend/decorators/@Repository"; | ||
export * from "@org/backend/decorators/@Transactional"; | ||
export * from "@org/backend/decorators/@Contract"; | ||
export * from "@org/backend/decorators/setup"; |
24 changes: 24 additions & 0 deletions
24
packages/backend/src/infrastructure/components/Database.ts
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Environment } from "@org/backend/config"; | ||
import { Injectable } from "@org/backend/decorators"; | ||
import { type Db } from "mongodb"; | ||
import { type AnyZodObject, type z } from "zod"; | ||
import app from "@org/backend/worker"; | ||
|
||
@Injectable("database") | ||
export class Database { | ||
#client: Db; | ||
|
||
get client() { | ||
if (this.#client) return this.#client; | ||
this.#client = app.mongoClient.db(Environment.getInstance().vars.DB_DATABASE); | ||
return this.#client; | ||
} | ||
|
||
collection<T extends AnyZodObject>(zodSchema: T) { | ||
const documentName = zodSchema.description; | ||
if (!documentName) throw new Error("No document name provided."); | ||
const lowerCaseName = documentName.toLowerCase(); | ||
const name = lowerCaseName.endsWith("s") ? lowerCaseName : `${lowerCaseName}s`; | ||
return this.client.collection<z.infer<T>>(name); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/backend/src/infrastructure/controllers/AuthController.ts
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
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
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
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
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
6 changes: 6 additions & 0 deletions
6
packages/backend/src/infrastructure/repository/ErrorLogRepository.ts
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { type ErrorLog } from "@org/shared"; | ||
import { type PaginableRepository } from "@org/backend/infrastructure/repository/PaginableRepository"; | ||
|
||
export interface ErrorLogRepository extends PaginableRepository<ErrorLog> { | ||
insertOne: (user: Omit<ErrorLog, "_id">) => Promise<ErrorLog>; | ||
} |
116 changes: 0 additions & 116 deletions
116
packages/backend/src/infrastructure/repository/MongoRepository.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...re/repository/interface/UserRepository.ts → ...frastructure/repository/UserRepository.ts
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
26 changes: 17 additions & 9 deletions
26
packages/backend/src/infrastructure/repository/impl/ErrorLogRepositoryImpl.ts
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
23 changes: 17 additions & 6 deletions
23
packages/backend/src/infrastructure/repository/impl/UserRepositoryImpl.ts
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
5 changes: 0 additions & 5 deletions
5
packages/backend/src/infrastructure/repository/interface/ErrorLogRepository.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.