-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Modify interTenantGetEntries * Fix schema * Fix after review * Add support orderBy to presentation JoinedEntryRevision * Refactor
- Loading branch information
1 parent
414f152
commit 01d44b7
Showing
11 changed files
with
149 additions
and
83 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,64 @@ | ||
import {raw} from 'objection'; | ||
import type {Knex} from 'knex'; | ||
import {COMPARISON_OPERATORS} from '../../../const'; | ||
import {InterTenantGetEntriesConfig} from '../../../types/models'; | ||
|
||
export type InterTenantGetEntriesArgs = Omit< | ||
InterTenantGetEntriesConfig, | ||
'page' | 'pageSize' | 'orderBy' | 'requestedBy' | ||
>; | ||
|
||
export const whereBuilderInterTenantGetEntries = ({ | ||
ids, | ||
type, | ||
createdBy, | ||
meta, | ||
creationTimeFilters, | ||
scope, | ||
createdAtFrom, | ||
}: InterTenantGetEntriesArgs & {createdAtFrom?: number}) => { | ||
return (builder: Knex.QueryBuilder) => { | ||
builder.where({ | ||
isDeleted: false, | ||
scope, | ||
}); | ||
|
||
if (ids) { | ||
if (Array.isArray(ids)) { | ||
builder.where('entries.entryId', 'in', ids); | ||
} else { | ||
builder.where('entries.entryId', ids); | ||
} | ||
} | ||
if (type) { | ||
builder.where('type', type); | ||
} | ||
if (createdBy) { | ||
builder.whereIn( | ||
'entries.createdBy', | ||
Array.isArray(createdBy) ? createdBy : [createdBy], | ||
); | ||
} | ||
if (meta) { | ||
Object.entries(meta).map(([metaField, value]) => { | ||
return builder.whereRaw('meta->>?::text = ?::text', [metaField, value]); | ||
}); | ||
} | ||
if (creationTimeFilters) { | ||
Object.entries(creationTimeFilters).forEach(([comparisonOperator, date]) => { | ||
const sqlComparisonOperator = COMPARISON_OPERATORS[comparisonOperator]; | ||
|
||
if (sqlComparisonOperator) { | ||
return builder.whereRaw('entries.created_at ? ?', [ | ||
raw(sqlComparisonOperator), | ||
date, | ||
]); | ||
} | ||
|
||
return; | ||
}); | ||
} else if (createdAtFrom) { | ||
builder.andWhere('entries.created_at', '>', raw('to_timestamp(?)', [createdAtFrom])); | ||
} | ||
}; | ||
}; |
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