-
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.
Refactor features with terms and conditions
I've updated the features controller creating a new dataservice for the terms collections in order to retrieve the user only the enabled terms and conditions version available.
- Loading branch information
1 parent
4f9bf8b
commit c5a15e7
Showing
10 changed files
with
118 additions
and
15 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 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,31 @@ | ||
import { model, property} from '@loopback/repository'; | ||
import { SearchableModel } from "./rsk/searchable-model"; | ||
|
||
@model() | ||
export class TermsDbDataModel implements SearchableModel { | ||
|
||
@property({ | ||
type: 'number', | ||
required: true, | ||
}) | ||
version: number; | ||
|
||
@property({ | ||
type: 'string', | ||
required: true, | ||
}) | ||
value: string; | ||
|
||
|
||
constructor(data?: Partial<TermsDbDataModel>) { | ||
Object.assign(this, data);; | ||
} | ||
|
||
getId() { | ||
return this.version; | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
getIdFieldName(): string { | ||
return "version"; | ||
} | ||
} |
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 @@ | ||
import { GenericDataService } from './generic-data-service'; | ||
import { TermsDbDataModel } from '../models'; | ||
|
||
export interface TermsDataService extends GenericDataService<TermsDbDataModel> { | ||
getVersion(version: number): Promise<TermsDbDataModel>; | ||
} |
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,44 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import mongoose from 'mongoose'; | ||
import {MongoDbDataService} from './mongodb-data.service'; | ||
import { TermsDbDataModel } from '../models'; | ||
import { TermsDataService } from './terms-data.service'; | ||
|
||
/* | ||
- THESE MODEL INTERFACES AND CLASSES ARE REQUIRED FOR MONGO BUT WE DON'T WANT THEM EXPOSED OUT OF THIS LAYER | ||
*/ | ||
interface TermsMongoModel extends mongoose.Document, TermsDbDataModel { | ||
} | ||
|
||
const TermsSchema = new mongoose.Schema({ | ||
version: {type: Number, required: true}, | ||
value: {type: String, required: true}, | ||
}); | ||
|
||
const TermsConnector = mongoose.model<TermsMongoModel>("Terms", TermsSchema); | ||
|
||
export class TermsMongoDbDataService extends MongoDbDataService<TermsDbDataModel, TermsMongoModel> implements TermsDataService { | ||
protected getByIdFilter(id: any) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
protected getManyFilter(filter?: any) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
protected getLoggerName(): string { | ||
return 'TermsMongoService'; | ||
} | ||
protected getConnector(): mongoose.Model<TermsMongoModel, {}, {}> { | ||
this.verifyAndCreateConnectionIfIsNecessary(); | ||
return TermsConnector; | ||
} | ||
async verifyAndCreateConnectionIfIsNecessary() { | ||
await this.ensureConnection(); | ||
} | ||
public async getVersion(version: number): Promise<TermsDbDataModel> { | ||
const [document] = await this.getConnector() | ||
.find({ version }) | ||
.exec(); | ||
return document; | ||
} | ||
|
||
} |