-
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
83beaca
commit a2ddeba
Showing
11 changed files
with
307 additions
and
172 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
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; | ||
} | ||
}; |
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,59 @@ | ||
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 DeleteCollectionsListReqBody = { | ||
collectionIds: string[]; | ||
}; | ||
|
||
const validateBody = makeSchemaValidator({ | ||
type: 'object', | ||
required: ['collectionIds'], | ||
properties: { | ||
collectionIds: { | ||
type: 'array', | ||
items: {type: 'string'}, | ||
}, | ||
}, | ||
}); | ||
|
||
export const deleteListController = async (req: Request, res: Response) => { | ||
const body = validateBody<DeleteCollectionsListReqBody>(req.body); | ||
|
||
const registry = req.ctx.get('registry'); | ||
const { | ||
controllersCallbacks: {onDeleteCollectionsListError, onDeleteCollectionsListSuccess}, | ||
} = registry.common.functions.get(); | ||
|
||
try { | ||
const result = await deleteCollections( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionIds: body.collectionIds, | ||
}, | ||
); | ||
|
||
onDeleteCollectionsListSuccess({ | ||
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) { | ||
onDeleteCollectionsListError({ | ||
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,24 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {getCollection} from '../../services/new/collection'; | ||
import {formatCollection} from '../../services/new/collection/formatters'; | ||
import Utils from '../../utils'; | ||
|
||
export const getCollectionController = async (req: Request, res: Response) => { | ||
const {params, query} = req; | ||
|
||
const result = await getCollection( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionId: params.collectionId, | ||
includePermissionsInfo: Utils.isTrueArg(query.includePermissionsInfo), | ||
}, | ||
); | ||
|
||
const formattedResponse = formatCollection(result); | ||
|
||
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 {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {getCollectionBreadcrumbs} from '../../services/new/collection'; | ||
import {formatGetCollectionBreadcrumbs} from '../../services/new/collection/formatters'; | ||
import Utils from '../../utils'; | ||
|
||
export const getCollectionBreadcrumbsController = async (req: Request, res: Response) => { | ||
const {params, query} = req; | ||
|
||
const result = await getCollectionBreadcrumbs( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionId: params.collectionId, | ||
includePermissionsInfo: Utils.isTrueArg(query.includePermissionsInfo), | ||
}, | ||
); | ||
|
||
const formattedResponse = formatGetCollectionBreadcrumbs(result); | ||
|
||
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,20 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {getCollectionsListByIds} from '../../services/new/collection'; | ||
import {formatCollectionModel} from '../../services/new/collection/formatters'; | ||
|
||
export const getCollectionsListByIdsController = async (req: Request, res: Response) => { | ||
const {body} = req; | ||
|
||
const result = await getCollectionsListByIds( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionIds: body.collectionIds, | ||
}, | ||
); | ||
|
||
const formattedResponse = result.map((instance) => formatCollectionModel(instance.model)); | ||
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,60 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import { | ||
Mode, | ||
OrderDirection, | ||
OrderField, | ||
getCollectionContent, | ||
} from '../../services/new/collection'; | ||
import {formatCollectionContent} from '../../services/new/collection/formatters'; | ||
import Utils from '../../utils'; | ||
|
||
/** | ||
* @deprecated for structureItemsController.getStructureItems, | ||
* @todo remove, after successful deploy with UI. | ||
* Exists for reverse compatibility. | ||
*/ | ||
export const getCollectionContentController = async (req: Request, res: Response) => { | ||
const {query} = req; | ||
|
||
let collectionsPage: Optional<Nullable<number>>; | ||
if (query.collectionsPage === 'null') { | ||
collectionsPage = null; | ||
} else { | ||
collectionsPage = query.collectionsPage | ||
? parseInt(query.collectionsPage as string, 10) | ||
: undefined; | ||
} | ||
|
||
let workbooksPage: Optional<Nullable<number>>; | ||
if (query.workbooksPage === 'null') { | ||
workbooksPage = null; | ||
} else { | ||
workbooksPage = query.workbooksPage | ||
? parseInt(query.workbooksPage as string, 10) | ||
: undefined; | ||
} | ||
|
||
const result = await getCollectionContent( | ||
{ctx: req.ctx}, | ||
{ | ||
collectionId: (query.collectionId as Optional<string>) ?? null, | ||
includePermissionsInfo: Utils.isTrueArg(query.includePermissionsInfo), | ||
filterString: query.filterString as Optional<string>, | ||
collectionsPage, | ||
workbooksPage, | ||
pageSize: query.pageSize ? parseInt(query.pageSize as string, 10) : undefined, | ||
orderField: query.orderField as Optional<OrderField>, | ||
orderDirection: query.orderDirection as Optional<OrderDirection>, | ||
onlyMy: Utils.isTrueArg(query.onlyMy), | ||
mode: query.mode as Optional<Mode>, | ||
}, | ||
); | ||
|
||
const formattedResponse = formatCollectionContent(result); | ||
|
||
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,12 @@ | ||
import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
||
import {prepareResponseAsync} from '../../components/response-presenter'; | ||
import {getRootCollectionPermissions} from '../../services/new/collection'; | ||
|
||
export const getRootCollectionPermissionsController = async (req: Request, res: Response) => { | ||
const result = await getRootCollectionPermissions({ctx: req.ctx}); | ||
|
||
const {code, response} = await prepareResponseAsync({data: result}); | ||
|
||
res.status(code).send(response); | ||
}; |
Oops, something went wrong.