-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
127 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
// ReferenceManager | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
// Models | ||
import { Reference } from '../../common/interfaces/models/reference'; | ||
|
||
// Resource Access | ||
import * as referenceRA from '../resource-access/reference'; | ||
|
||
// Utilities | ||
import { FilterToken } from '../routes/utils'; | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
export async function list(filters : Record<string, FilterToken>, tableName : string) : Promise<Reference[]> | ||
{ | ||
return referenceRA.list(filters, tableName); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
// Reference Resource Access | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
// Models | ||
import { Reference } from '../../common/interfaces/models/reference'; | ||
|
||
// Transforms | ||
import * as ReferenceTrans from './transforms/reference'; | ||
|
||
// Utils | ||
import { isEmpty } from '../utils/misc'; | ||
import { getDB } from '../utils/database'; | ||
import { applyFilters } from '../knex/utils'; | ||
import { FilterToken } from '../routes/utils'; | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
export async function list(filters : Record<string, FilterToken>, tableName : string) : Promise<Reference[]> | ||
{ | ||
const db = await getDB(); | ||
let query = db(tableName) | ||
.select(`${ tableName }.name`, `${ tableName }.abbr`, `${ tableName }.product_code as productCode`); | ||
|
||
if(filters && !isEmpty(filters)) | ||
{ | ||
query = applyFilters(query, filters); | ||
} | ||
|
||
return (await query).map(ReferenceTrans.fromDB); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- |
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,35 @@ | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// Reference Database Transform | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
import { Reference } from '../../../common/interfaces/models/reference'; | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
export interface ReferenceDBSchema { | ||
abbr : string; | ||
name : string; | ||
productCode : string; | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
export function toDB(reference : Reference) : ReferenceDBSchema | ||
{ | ||
return { | ||
abbr: reference.abbr, | ||
name: reference.name, | ||
productCode: reference.productCode | ||
}; | ||
} | ||
|
||
export function fromDB(reference : ReferenceDBSchema) : Reference | ||
{ | ||
return { | ||
abbr: reference.abbr, | ||
name: reference.name, | ||
productCode: reference.productCode | ||
}; | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- |
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