-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#14 - Added item endpoint, to get item with extra data (Folder, Blob,…
… etc.)
- Loading branch information
1 parent
5347359
commit 0bbcf41
Showing
13 changed files
with
328 additions
and
42 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
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,56 @@ | ||
import { FastifyReply, FastifyRequest } from 'fastify'; | ||
import ItemService from './item.service'; | ||
import { ReadInput } from './item.schema'; | ||
import AccessService from './sharing/access.service'; | ||
|
||
export default class ItemController { | ||
private itemService: ItemService; | ||
private accessService: AccessService; | ||
|
||
constructor(itemService: ItemService, accessService: AccessService) { | ||
this.itemService = itemService; | ||
this.accessService = accessService; | ||
} | ||
|
||
public async browseHandler(request: FastifyRequest, reply: FastifyReply) { | ||
try { | ||
const items = await this.itemService.getByOwnerIdAndParentId(request.user.sub, null); | ||
|
||
return reply.code(200).send(items); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
return reply.badRequest(request.i18n.t(e.message)); | ||
} | ||
Check warning on line 23 in src/modules/item/item.controller.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
|
||
/* istanbul ignore next */ | ||
return reply.badRequest(); | ||
} | ||
} | ||
|
||
public async readHandler( | ||
request: FastifyRequest<{ | ||
Params: ReadInput; | ||
}>, | ||
reply: FastifyReply, | ||
) { | ||
try { | ||
if (!(await this.accessService.hasAccessToItem(request.params.parentId, request.user.sub))) { | ||
return reply.unauthorized(); | ||
} | ||
Check warning on line 39 in src/modules/item/item.controller.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
|
||
const items = await this.itemService.getByOwnerIdAndParentIdAndSharred( | ||
request.user.sub, | ||
request.params.parentId, | ||
); | ||
|
||
return reply.code(200).send(items); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
return reply.badRequest(request.i18n.t(e.message)); | ||
} | ||
Check warning on line 50 in src/modules/item/item.controller.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
|
||
/* istanbul ignore next */ | ||
return reply.badRequest(); | ||
} | ||
} | ||
} |
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,46 @@ | ||
import { FastifyInstance } from 'fastify'; | ||
import ItemController from './item.controller'; | ||
import ItemService from './item.service'; | ||
|
||
export default async (fastify: FastifyInstance) => { | ||
const itemController = new ItemController(new ItemService()); | ||
|
||
fastify.get( | ||
'/', | ||
{ | ||
schema: { | ||
tags: ['Items'], | ||
response: { | ||
200: { $ref: 'itemsResponseSchema' }, | ||
}, | ||
security: [ | ||
{ | ||
bearerAuth: [], | ||
}, | ||
], | ||
}, | ||
onRequest: [fastify.authenticate], | ||
}, | ||
itemController.browseHandler.bind(itemController), | ||
); | ||
|
||
fastify.get( | ||
'/:parentId', | ||
{ | ||
schema: { | ||
tags: ['Items'], | ||
params: { $ref: 'readItemsSchema' }, | ||
response: { | ||
200: { $ref: 'itemsResponseSchema' }, | ||
}, | ||
security: [ | ||
{ | ||
bearerAuth: [], | ||
}, | ||
], | ||
}, | ||
onRequest: [fastify.authenticate], | ||
}, | ||
itemController.readHandler.bind(itemController), | ||
); | ||
}; |
Oops, something went wrong.