-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getEntriesData endpoint #227
Open
stepanenkoxx
wants to merge
7
commits into
main
Choose a base branch
from
CHARTS-10806-add-get-entries-data-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c70679a
Add getEntriesData endpoint
stepanenkoxx 3292ab3
Add dlsEnabled check
stepanenkoxx 0bc143c
Add getEntriesData endpoint
stepanenkoxx af8e47b
Fix generic type
stepanenkoxx 6f3ce39
Fix checkFolderEntriesPermissions
stepanenkoxx 94088c2
Add getEntriesData endpoint
stepanenkoxx 5cc2ab8
fix checkBulkPermission type
stepanenkoxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,2 @@ | ||
export const NOT_FOUND_ERROR_CODE = 'NOT_FOUND'; | ||
export const ACCESS_DENIED_ERROR_CODE = 'ACCESS_DENIED'; |
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,61 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../../components/response-presenter'; | ||
import {makeSchemaValidator} from '../../../components/validation-schema-compiler'; | ||
import {ALLOWED_SCOPE_VALUES} from '../../../const'; | ||
import {EntryScope} from '../../../db/models/new/entry/types'; | ||
import {getJoinedEntriesRevisionsByIds} from '../../../services/new/entry'; | ||
|
||
import type {GetEntriesDataResponseBody} from './types'; | ||
import {formatGetEntriesDataResponse} from './utils'; | ||
|
||
type GetEntriesDataRequestBody = { | ||
entryIds: string[]; | ||
scope?: EntryScope; | ||
type?: string; | ||
fields: string[]; | ||
}; | ||
|
||
const validateBody = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['entryIds', 'fields'], | ||
properties: { | ||
entryIds: { | ||
type: 'array', | ||
items: {type: 'string'}, | ||
}, | ||
scope: { | ||
type: 'string', | ||
enum: ALLOWED_SCOPE_VALUES, | ||
}, | ||
type: { | ||
type: 'string', | ||
}, | ||
fields: { | ||
type: 'array', | ||
items: {type: 'string'}, | ||
}, | ||
}, | ||
}); | ||
|
||
export const getEntriesDataController = async ( | ||
req: Request, | ||
res: Response<GetEntriesDataResponseBody>, | ||
) => { | ||
const body = validateBody<GetEntriesDataRequestBody>(req.body); | ||
|
||
const result = await getJoinedEntriesRevisionsByIds( | ||
{ctx: req.ctx}, | ||
{ | ||
entryIds: body.entryIds, | ||
scope: body.scope, | ||
type: body.type, | ||
}, | ||
); | ||
|
||
const formattedResponse = formatGetEntriesDataResponse({result, fields: body.fields}); | ||
|
||
const {code, response} = await prepareResponseAsync({data: formattedResponse}); | ||
|
||
res.status(code).send(response); | ||
}; |
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,24 @@ | ||
import {EntryScope} from '../../../db/models/new/entry/types'; | ||
|
||
import {ACCESS_DENIED_ERROR_CODE, NOT_FOUND_ERROR_CODE} from './constants'; | ||
|
||
export type GetEntriesDataResponseItemResult = { | ||
scope: Nullable<EntryScope>; | ||
type: string; | ||
data: Record<string, unknown>; | ||
}; | ||
|
||
export type GetEntriesDataResponseItem = { | ||
entryId: string; | ||
} & ( | ||
| { | ||
result: GetEntriesDataResponseItemResult; | ||
} | ||
| { | ||
error: { | ||
code: typeof NOT_FOUND_ERROR_CODE | typeof ACCESS_DENIED_ERROR_CODE; | ||
}; | ||
} | ||
); | ||
|
||
export type GetEntriesDataResponseBody = GetEntriesDataResponseItem[]; |
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 _ from 'lodash'; | ||
|
||
import type {GetJoinedEntriesRevisionsByIdsResult} from '../../../services/new/entry'; | ||
|
||
import {ACCESS_DENIED_ERROR_CODE, NOT_FOUND_ERROR_CODE} from './constants'; | ||
import type {GetEntriesDataResponseBody, GetEntriesDataResponseItemResult} from './types'; | ||
|
||
export const formatGetEntriesDataResponse = ({ | ||
result, | ||
fields, | ||
}: { | ||
result: GetJoinedEntriesRevisionsByIdsResult; | ||
fields: string[]; | ||
}): GetEntriesDataResponseBody => { | ||
const {entries, notFoundEntryIds, accessDeniedEntryIds} = result; | ||
|
||
const formattedResult: GetEntriesDataResponseBody = []; | ||
|
||
entries.forEach(({entryId, scope, type, data}) => { | ||
let responseData: GetEntriesDataResponseItemResult['data']; | ||
|
||
if (data) { | ||
responseData = fields.reduce<GetEntriesDataResponseItemResult['data']>( | ||
(acc, fieldPath) => { | ||
acc[fieldPath] = _.get(data, fieldPath); | ||
|
||
return acc; | ||
}, | ||
{}, | ||
); | ||
} else { | ||
responseData = {}; | ||
} | ||
|
||
formattedResult.push({ | ||
entryId, | ||
result: { | ||
scope, | ||
type, | ||
data: responseData, | ||
}, | ||
}); | ||
}); | ||
|
||
notFoundEntryIds.forEach((entryId) => { | ||
formattedResult.push({entryId, error: {code: NOT_FOUND_ERROR_CODE}}); | ||
}); | ||
|
||
accessDeniedEntryIds.forEach((entryId) => { | ||
formattedResult.push({entryId, error: {code: ACCESS_DENIED_ERROR_CODE}}); | ||
}); | ||
|
||
return formattedResult; | ||
}; |
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 |
---|---|---|
|
@@ -11,10 +11,10 @@ export interface DLSConstructor { | |
checkPermissionsArgs: MT.CheckPermissionDlsConfig, | ||
) => Promise<any>; | ||
|
||
checkBulkPermission( | ||
checkBulkPermission<E extends object>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should probably be {entryId: string} not object |
||
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, | ||
checkBulkPermissionArgs: MT.CheckBulkPermissionsDlsConfig, | ||
): Promise<any[]>; | ||
checkBulkPermissionArgs: MT.CheckBulkPermissionsDlsConfig<E>, | ||
): Promise<Array<E & MT.DlsEntity>>; | ||
|
||
addEntity( | ||
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have nullable type in our Entry model
Can it really be null?