Skip to content

Commit f6ea2e6

Browse files
author
Roman Snapko
authored
Add request schemas for project endpoints (#1701)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Fixes OPS-3115. Simply added schemas to remove the token from the response
1 parent 27957be commit f6ea2e6

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';
2-
import { ApplicationError, ErrorCode } from '@openops/shared';
1+
import {
2+
FastifyPluginCallbackTypebox,
3+
Type,
4+
} from '@fastify/type-provider-typebox';
5+
import {
6+
ApplicationError,
7+
ErrorCode,
8+
Project,
9+
SeekPage,
10+
} from '@openops/shared';
311
import { paginationHelper } from '../helper/pagination/pagination-utils';
412
import { projectService } from './project-service';
513

@@ -8,23 +16,45 @@ export const userProjectController: FastifyPluginCallbackTypebox = (
816
_opts,
917
done,
1018
) => {
11-
fastify.get('/:id', async (request, response) => {
12-
try {
13-
return await projectService.getOneOrThrow(request.principal.projectId);
14-
} catch (err) {
15-
if (err instanceof ApplicationError) {
16-
err.error.code = ErrorCode.ENTITY_NOT_FOUND;
17-
return response.code(401).send();
19+
fastify.get(
20+
'/:id',
21+
GetUserProjectRequestOptions,
22+
async (request, response) => {
23+
try {
24+
return await projectService.getOneOrThrow(request.principal.projectId);
25+
} catch (err) {
26+
if (err instanceof ApplicationError) {
27+
err.error.code = ErrorCode.ENTITY_NOT_FOUND;
28+
return response.code(401).send();
29+
}
30+
throw err;
1831
}
19-
throw err;
20-
}
21-
});
32+
},
33+
);
2234

23-
fastify.get('/', async (request) => {
35+
fastify.get('/', ListUserProjectsRequestOptions, async (request) => {
2436
return paginationHelper.createPage(
2537
[await projectService.getOneOrThrow(request.principal.projectId)],
2638
null,
2739
);
2840
});
2941
done();
3042
};
43+
44+
const ProjectWithoutToken = Type.Omit(Project, ['tablesDatabaseToken']);
45+
46+
const GetUserProjectRequestOptions = {
47+
schema: {
48+
response: {
49+
200: ProjectWithoutToken,
50+
},
51+
},
52+
};
53+
54+
const ListUserProjectsRequestOptions = {
55+
schema: {
56+
response: {
57+
200: SeekPage(ProjectWithoutToken),
58+
},
59+
},
60+
};

0 commit comments

Comments
 (0)