-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: seperate content price to model collection
- Loading branch information
abdulhakim2902
committed
Dec 8, 2022
1 parent
8c6c901
commit e382298
Showing
12 changed files
with
217 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {Entity, model, property, belongsTo} from '@loopback/repository'; | ||
import {Currency} from './currency.model'; | ||
import {UnlockableContent} from './unlockable-content.model'; | ||
|
||
@model({ | ||
settings: { | ||
strictObjectIDCoercion: true, | ||
mongodb: { | ||
collection: 'contentPrices', | ||
}, | ||
}, | ||
}) | ||
export class ContentPrice extends Entity { | ||
@property({ | ||
type: 'string', | ||
id: true, | ||
generated: true, | ||
mongodb: { | ||
dataType: 'ObjectId', | ||
}, | ||
}) | ||
id: string; | ||
|
||
@property({ | ||
type: 'number', | ||
required: true, | ||
}) | ||
amount: number; | ||
|
||
@belongsTo(() => Currency) | ||
currencyId: string; | ||
|
||
@belongsTo(() => UnlockableContent) | ||
unlockableContentId: string; | ||
|
||
constructor(data?: Partial<ContentPrice>) { | ||
super(data); | ||
} | ||
} | ||
|
||
export interface ContentPriceRelations { | ||
// describe navigational properties here | ||
} | ||
|
||
export type ContentPriceWithRelations = ContentPrice & ContentPriceRelations; |
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,54 @@ | ||
import {inject, Getter} from '@loopback/core'; | ||
import { | ||
DefaultCrudRepository, | ||
repository, | ||
BelongsToAccessor, | ||
} from '@loopback/repository'; | ||
import {MongoDataSource} from '../datasources'; | ||
import { | ||
ContentPrice, | ||
ContentPriceRelations, | ||
Currency, | ||
UnlockableContent, | ||
} from '../models'; | ||
import {CurrencyRepository} from './currency.repository'; | ||
import {UnlockableContentRepository} from './unlockable-content.repository'; | ||
|
||
export class ContentPriceRepository extends DefaultCrudRepository< | ||
ContentPrice, | ||
typeof ContentPrice.prototype.id, | ||
ContentPriceRelations | ||
> { | ||
public readonly currency: BelongsToAccessor< | ||
Currency, | ||
typeof ContentPrice.prototype.id | ||
>; | ||
|
||
public readonly unlockableContent: BelongsToAccessor< | ||
UnlockableContent, | ||
typeof ContentPrice.prototype.id | ||
>; | ||
|
||
constructor( | ||
@inject('datasources.mongo') dataSource: MongoDataSource, | ||
@repository.getter('CurrencyRepository') | ||
protected currencyRepositoryGetter: Getter<CurrencyRepository>, | ||
@repository.getter('UnlockableContentRepository') | ||
protected unlockableContentRepositoryGetter: Getter<UnlockableContentRepository>, | ||
) { | ||
super(ContentPrice, dataSource); | ||
this.unlockableContent = this.createBelongsToAccessorFor( | ||
'unlockableContent', | ||
unlockableContentRepositoryGetter, | ||
); | ||
this.registerInclusionResolver( | ||
'unlockableContent', | ||
this.unlockableContent.inclusionResolver, | ||
); | ||
this.currency = this.createBelongsToAccessorFor( | ||
'currency', | ||
currencyRepositoryGetter, | ||
); | ||
this.registerInclusionResolver('currency', this.currency.inclusionResolver); | ||
} | ||
} |
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
Oops, something went wrong.