-
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 controllers callbacks #221
Open
stepanenkoxx
wants to merge
8
commits into
main
Choose a base branch
from
CHARTS-10741-add-controllers-callbacks
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
8 commits
Select commit
Hold shift + click to select a range
074024f
Add controllers callbacks
stepanenkoxx e8ea9ab
move create collection validatation to controller
stepanenkoxx a2257c0
fix ts
stepanenkoxx 0ee60c7
fix validation
stepanenkoxx 4c2afe5
fix validation
stepanenkoxx 83beaca
Add controllers callbacks
stepanenkoxx a2ddeba
Add controllers callbacks
stepanenkoxx 16832b4
Disable allErrors settings for Ajv
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
export type {DLSConstructor} from '../../src/registry/common/components/dls/types'; | ||
export type { | ||
OnCreateCollectionError, | ||
OnCreateCollectionSuccess, | ||
OnMoveCollectionError, | ||
OnMoveCollectionSuccess, | ||
OnMoveCollectionsListError, | ||
OnMoveCollectionsListSuccess, | ||
OnUpdateCollectionError, | ||
OnUpdateCollectionSuccess, | ||
OnDeleteCollectionError, | ||
OnDeleteCollectionSuccess, | ||
OnDeleteCollectionsListError, | ||
OnDeleteCollectionsListSuccess, | ||
} from '../../src/registry/common/utils/controllers-callbacks/collections'; | ||
export type {GatewayApi} from '../../src/registry'; |
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 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,67 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {makeSchemaValidator} from '../../components/validation-schema-compiler'; | ||
import {createCollection} from '../../services/new/collection'; | ||
import {formatCollectionWithOperation} from '../../services/new/collection/formatters'; | ||
|
||
export type CreateCollectionReqBody = { | ||
title: string; | ||
description?: string; | ||
parentId: Nullable<string>; | ||
}; | ||
|
||
const validateBody = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['title', 'parentId'], | ||
properties: { | ||
title: { | ||
type: 'string', | ||
}, | ||
description: { | ||
type: 'string', | ||
}, | ||
parentId: { | ||
type: ['string', 'null'], | ||
}, | ||
}, | ||
}); | ||
|
||
export const createCollectionController = async (req: Request, res: Response) => { | ||
const body = validateBody<CreateCollectionReqBody>(req.body); | ||
|
||
const registry = req.ctx.get('registry'); | ||
const { | ||
controllersCallbacks: {onCreateCollectionError, onCreateCollectionSuccess}, | ||
} = registry.common.functions.get(); | ||
|
||
try { | ||
const result = await createCollection( | ||
{ctx: req.ctx}, | ||
{ | ||
title: body.title, | ||
description: body.description, | ||
parentId: body.parentId, | ||
}, | ||
); | ||
|
||
onCreateCollectionSuccess({ | ||
ctx: req.ctx, | ||
reqBody: body, | ||
collection: result.collection.model, | ||
}); | ||
|
||
const formattedResponse = formatCollectionWithOperation( | ||
result.collection, | ||
result.operation, | ||
); | ||
|
||
const {code, response} = await prepareResponseAsync({data: formattedResponse}); | ||
|
||
res.status(code).send(response); | ||
} catch (error) { | ||
onCreateCollectionError({ctx: req.ctx, reqBody: body, error}); | ||
|
||
throw error; | ||
} | ||
}; |
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 {Request, Response} from 'express'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {makeSchemaValidator} from '../../components/validation-schema-compiler'; | ||
import {deleteCollections} from '../../services/new/collection'; | ||
import {formatCollectionModelsList} from '../../services/new/collection/formatters'; | ||
|
||
export type DeleteCollectionReqParams = { | ||
collectionId: string; | ||
}; | ||
|
||
const validateParams = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['collectionId'], | ||
properties: { | ||
collectionId: { | ||
type: 'string', | ||
}, | ||
}, | ||
}); | ||
|
||
export const deleteCollectionController = async (req: Request, res: Response) => { | ||
const params = validateParams(req.params) as DeleteCollectionReqParams; | ||
|
||
const registry = req.ctx.get('registry'); | ||
const { | ||
controllersCallbacks: {onDeleteCollectionError, onDeleteCollectionSuccess}, | ||
} = registry.common.functions.get(); | ||
|
||
try { | ||
const result = await deleteCollections( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionIds: [params.collectionId], | ||
}, | ||
); | ||
|
||
onDeleteCollectionSuccess({ | ||
ctx: req.ctx, | ||
reqParams: params, | ||
collections: result.collections, | ||
}); | ||
|
||
const formattedResponse = formatCollectionModelsList(result); | ||
|
||
const {code, response} = await prepareResponseAsync({data: formattedResponse}); | ||
|
||
res.status(code).send(response); | ||
} catch (error) { | ||
onDeleteCollectionError({ctx: req.ctx, reqParams: params, error}); | ||
|
||
throw error; | ||
} | ||
}; |
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.
Fixed this issue of "Code scanning results / CodeQL" check
I guess we don't need to check all errors