-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepared ground for service implementation
- Loading branch information
zhamdi
committed
Oct 3, 2023
1 parent
1ff0693
commit afb47b1
Showing
16 changed files
with
143 additions
and
44 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export interface IBaseDAO<D extends object> { | ||
// Count documents that match a query | ||
count(query: object): Promise<number>; | ||
|
||
// Create a new document | ||
create(data: Partial<D>): Promise<D>; | ||
|
||
// Delete a document by ID | ||
deleteById(userId: string): Promise<boolean>; | ||
|
||
// Find documents that match a query | ||
find(query: object): Promise<D[]>; | ||
|
||
findById(userId: object): Promise<D | null>; | ||
|
||
// Update a document by ID | ||
updateById(userId: string, update: Partial<D>): Promise<D | null>; | ||
} |
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,17 @@ | ||
import { IOffer } from "../model/IOffer"; | ||
import { IOrder } from "../model/IOrder"; | ||
import { ITokenTimetable } from "../model/ITokenTimetable"; | ||
import { IUserCredits } from "../model/IUserCredits"; | ||
import { | ||
IOfferDao, | ||
IOrderDao, | ||
ITokenTimetableDao, | ||
IUserCreditsDao, | ||
} from "./index"; | ||
|
||
export interface IDaoFactory<K> { | ||
getOfferDao(): IOfferDao<K, IOffer<K>>; | ||
getOrderDao(): IOrderDao<K, IOrder<K>>; | ||
getTokenTimetableDao(): ITokenTimetableDao<K, ITokenTimetable<K>>; | ||
getUserCreditsDao(): IUserCreditsDao<K, IUserCredits<K>>; | ||
} |
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 {IOffer} from "../model/IOffer"; | ||
import {IBaseDAO} from "./IBaseDAO"; | ||
|
||
export interface IOfferDao<K extends object, D extends IOffer<K>> | ||
extends IBaseDAO<D> { | ||
} |
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 {IOrder} from "../model/IOrder"; | ||
import {IBaseDAO} from "./IBaseDAO"; | ||
|
||
export interface IOrderDao<K extends object, D extends IOrder<K>> | ||
extends IBaseDAO<D> { | ||
} |
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,7 @@ | ||
import { ITokenTimetable } from "../model/ITokenTimetable"; | ||
import {IBaseDAO} from "./IBaseDAO"; | ||
|
||
export interface ITokenTimetableDao< | ||
K extends object, | ||
D extends ITokenTimetable<K>, | ||
> extends IBaseDAO<D> {} |
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,7 @@ | ||
import {ISubscription, IUserCredits} from "../model/IUserCredits"; | ||
import {IBaseDAO} from "./IBaseDAO"; | ||
|
||
export interface IUserCreditsDao<K extends object, D extends IUserCredits<K>> | ||
extends IBaseDAO<D> { | ||
findByUserId(userId: K): Promise<ISubscription<K>[]>; | ||
} |
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,35 +1,7 @@ | ||
import { IOffer } from "../model/IOffer"; | ||
import { IOrder } from "../model/IOrder"; | ||
import { ISubscription, IUserCredits } from "../model/IUserCredits"; | ||
// index.ts | ||
|
||
export interface IUserCreditsDao<K extends object, D extends IUserCredits<K>> | ||
extends BaseDAO<D> { | ||
findByUserId(userId: K): Promise<ISubscription<K>[]>; | ||
} | ||
|
||
export interface IOfferDao<K extends object, D extends IOffer<K>> | ||
extends BaseDAO<D> {} | ||
|
||
export interface IOrderDao<K extends object, D extends IOrder<K>> | ||
extends BaseDAO<D> {} | ||
|
||
export interface ISubscriptionDao<K extends object> extends BaseDAO<K> {} | ||
|
||
export interface BaseDAO<D extends object> { | ||
// Count documents that match a query | ||
count(query: object): Promise<number>; | ||
|
||
// Create a new document | ||
create(data: Partial<D>): Promise<D>; | ||
|
||
// Delete a document by ID | ||
deleteById(userId: string): Promise<boolean>; | ||
|
||
// Find documents that match a query | ||
find(query: object): Promise<D[]>; | ||
|
||
findById(userId: object): Promise<D | null>; | ||
|
||
// Update a document by ID | ||
updateById(userId: string, update: Partial<D>): Promise<D | null>; | ||
} | ||
export { IDaoFactory } from "./IDaoFactory"; | ||
export { IOfferDao } from "./IOfferDao"; | ||
export { IOrderDao } from "./IOrderDao"; | ||
export { ITokenTimetableDao } from "./ITokenTimetableDao"; | ||
export { IUserCreditsDao } from "./IUserCreditsDao"; |
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 @@ | ||
// index.ts | ||
|
||
export { IOffer } from "./IOffer"; | ||
export { IOrder } from "./IOrder"; | ||
export { ITokenTimetable } from "./ITokenTimetable"; | ||
export { IUserCredits } from "./IUserCredits"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ObjectId } from "mongoose"; | ||
|
||
import { | ||
IDaoFactory, | ||
IOfferDao, | ||
IOrderDao, | ||
ITokenTimetableDao, | ||
IUserCreditsDao, | ||
} from "../../../db/dao"; | ||
import { | ||
IOffer, | ||
IOrder, | ||
ITokenTimetable, | ||
IUserCredits, | ||
} from "../../../db/model"; | ||
import { OfferDao, OrderDao, TokenTimetableDao, UserCreditsDao } from "."; | ||
|
||
export class MongooseDaoFactory implements IDaoFactory<ObjectId> { | ||
private readonly offerDao; | ||
private readonly orderDao; | ||
private readonly tokenTimetableDao; | ||
private readonly userCreditsDao; | ||
|
||
constructor( | ||
private uri: string, | ||
private dbName: string, | ||
) { | ||
this.offerDao = new OfferDao(uri, dbName); | ||
this.orderDao = new OrderDao(uri, dbName); | ||
this.tokenTimetableDao = new TokenTimetableDao(uri, dbName); | ||
this.userCreditsDao = new UserCreditsDao(uri, dbName); | ||
} | ||
|
||
getOfferDao(): IOfferDao<ObjectId, IOffer<ObjectId>> { | ||
return this.offerDao; | ||
} | ||
|
||
getOrderDao(): IOrderDao<ObjectId, IOrder<ObjectId>> { | ||
return this.orderDao; | ||
} | ||
|
||
getTokenTimetableDao(): ITokenTimetableDao< | ||
ObjectId, | ||
ITokenTimetable<ObjectId> | ||
> { | ||
return this.tokenTimetableDao; | ||
} | ||
|
||
getUserCreditsDao(): IUserCreditsDao<ObjectId, IUserCredits<ObjectId>> { | ||
return this.userCreditsDao; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// index.ts | ||
|
||
export { OfferDao } from "./OfferDao"; | ||
export { OrderDao } from "./OrderDao"; | ||
export { TokenTimetableDao } from "./TokenTimetableDao"; | ||
export { UserCreditsDao } from "./UserCreditsDao"; |
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