-
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.
- Loading branch information
1 parent
4c2afe5
commit 83beaca
Showing
11 changed files
with
310 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {makeSchemaValidator} from '../../components/validation-schema-compiler'; | ||
import {moveCollection} from '../../services/new/collection'; | ||
import {formatCollectionModel} from '../../services/new/collection/formatters'; | ||
|
||
export type MoveCollectionReqBody = { | ||
parentId: Nullable<string>; | ||
title?: string; | ||
}; | ||
|
||
const validateBody = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['parentId'], | ||
properties: { | ||
parentId: { | ||
type: ['string', 'null'], | ||
}, | ||
title: { | ||
type: 'string', | ||
}, | ||
}, | ||
}); | ||
|
||
export type MoveCollectionReqParams = { | ||
collectionId: string; | ||
}; | ||
|
||
const validateParams = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['collectionId'], | ||
properties: { | ||
collectionId: { | ||
type: 'string', | ||
}, | ||
}, | ||
}); | ||
|
||
export const moveCollectionController = async (req: Request, res: Response) => { | ||
const body = validateBody<MoveCollectionReqBody>(req.body); | ||
const params = validateParams(req.params) as MoveCollectionReqParams; | ||
|
||
const registry = req.ctx.get('registry'); | ||
const { | ||
controllersCallbacks: {onMoveCollectionError, onMoveCollectionSuccess}, | ||
} = registry.common.functions.get(); | ||
|
||
try { | ||
const result = await moveCollection( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionId: params.collectionId, | ||
parentId: body.parentId, | ||
title: body.title, | ||
}, | ||
); | ||
|
||
onMoveCollectionSuccess({ | ||
ctx: req.ctx, | ||
reqBody: body, | ||
reqParams: params, | ||
collection: result, | ||
}); | ||
|
||
const formattedResponse = formatCollectionModel(result); | ||
|
||
const {code, response} = await prepareResponseAsync({data: formattedResponse}); | ||
|
||
res.status(code).send(response); | ||
} catch (error) { | ||
onMoveCollectionError({ | ||
ctx: req.ctx, | ||
reqBody: body, | ||
reqParams: params, | ||
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,64 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {makeSchemaValidator} from '../../components/validation-schema-compiler'; | ||
import {moveCollectionsList} from '../../services/new/collection'; | ||
import {formatCollectionModelsList} from '../../services/new/collection/formatters'; | ||
|
||
export type MoveCollectionsListReqBody = { | ||
collectionIds: string[]; | ||
parentId: Nullable<string>; | ||
}; | ||
|
||
const validateBody = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['collectionIds', 'parentId'], | ||
properties: { | ||
collectionIds: { | ||
type: 'array', | ||
items: {type: 'string'}, | ||
}, | ||
parentId: { | ||
type: ['string', 'null'], | ||
}, | ||
}, | ||
}); | ||
|
||
export const moveCollectionsListController = async (req: Request, res: Response) => { | ||
const body = validateBody<MoveCollectionsListReqBody>(req.body); | ||
|
||
const registry = req.ctx.get('registry'); | ||
const { | ||
controllersCallbacks: {onMoveCollectionsListError, onMoveCollectionsListSuccess}, | ||
} = registry.common.functions.get(); | ||
|
||
try { | ||
const result = await moveCollectionsList( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionIds: body.collectionIds, | ||
parentId: body.parentId, | ||
}, | ||
); | ||
|
||
onMoveCollectionsListSuccess({ | ||
ctx: req.ctx, | ||
reqBody: body, | ||
collections: result.collections, | ||
}); | ||
|
||
const formattedResponse = formatCollectionModelsList(result); | ||
|
||
const {code, response} = await prepareResponseAsync({data: formattedResponse}); | ||
|
||
res.status(code).send(response); | ||
} catch (error) { | ||
onMoveCollectionsListError({ | ||
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,80 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {makeSchemaValidator} from '../../components/validation-schema-compiler'; | ||
import {updateCollection} from '../../services/new/collection'; | ||
import {formatCollectionModel} from '../../services/new/collection/formatters'; | ||
|
||
export type UpdateCollectionReqBody = { | ||
title?: string; | ||
description?: string; | ||
}; | ||
|
||
const validateBody = makeSchemaValidator({ | ||
type: 'object', | ||
properties: { | ||
title: { | ||
type: 'string', | ||
}, | ||
description: { | ||
type: 'string', | ||
}, | ||
}, | ||
}); | ||
|
||
export type UpdateCollectionReqParams = { | ||
collectionId: string; | ||
}; | ||
|
||
const validateParams = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['collectionId'], | ||
properties: { | ||
collectionId: { | ||
type: 'string', | ||
}, | ||
}, | ||
}); | ||
|
||
export const updateCollectionController = async (req: Request, res: Response) => { | ||
const body = validateBody<UpdateCollectionReqBody>(req.body); | ||
const params = validateParams(req.params) as UpdateCollectionReqParams; | ||
|
||
const registry = req.ctx.get('registry'); | ||
const { | ||
controllersCallbacks: {onUpdateCollectionError, onUpdateCollectionSuccess}, | ||
} = registry.common.functions.get(); | ||
|
||
try { | ||
const result = await updateCollection( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionId: params.collectionId, | ||
title: body.title, | ||
description: body.description, | ||
}, | ||
); | ||
|
||
onUpdateCollectionSuccess({ | ||
ctx: req.ctx, | ||
reqBody: body, | ||
reqParams: params, | ||
collection: result, | ||
}); | ||
|
||
const formattedResponse = formatCollectionModel(result); | ||
|
||
const {code, response} = await prepareResponseAsync({data: formattedResponse}); | ||
|
||
res.status(code).send(response); | ||
} catch (error) { | ||
onUpdateCollectionError({ | ||
ctx: req.ctx, | ||
reqBody: body, | ||
reqParams: params, | ||
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
Oops, something went wrong.