Skip to content
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

fix user controller v2 #233

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions packages/api/src/controllers/v2/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class UserController {
avatarMediaPath,
email,
gender,
bio,
overwrite,
recover,
} = req.body;
Expand All @@ -44,14 +45,22 @@ class UserController {
avatarMediaPath,
email,
gender,
bio,
trust: {
phone,
},
},
overwrite,
recover
)
.then((user) => standardResponse(res, 201, true, user))
.then((user) =>
standardResponse(res, 201, true, {
...user,
age: user.year
? new Date().getUTCFullYear() - user.year
: null,
})
)
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};

Expand Down Expand Up @@ -100,6 +109,7 @@ class UserController {
avatarMediaPath,
email,
gender,
bio,
} = req.body;
this.userService
.update({
Expand All @@ -114,8 +124,16 @@ class UserController {
avatarMediaPath,
email,
gender,
bio,
})
.then((r) => standardResponse(res, 200, true, r))
.then((user) =>
standardResponse(res, 200, true, {
...user,
age: user.year
? new Date().getUTCFullYear() - user.year
: null,
})
)
.catch((e) =>
standardResponse(res, 400, false, '', { error: e.message })
);
Expand Down Expand Up @@ -176,7 +194,12 @@ class UserController {

const { type, entity } = req.query;

if (type === undefined || entity === undefined) {
if (
type === undefined ||
entity === undefined ||
!(typeof type === 'string') ||
!(typeof entity === 'string')
) {
standardResponse(res, 400, false, '', {
error: {
name: 'INVALID_QUERY',
Expand All @@ -187,7 +210,7 @@ class UserController {
}

this.userLogService
.get(req.user.address, type as string, entity as string)
.get(req.user.address, type, entity)
.then((r) => standardResponse(res, 201, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
Expand All @@ -203,8 +226,20 @@ class UserController {
return;
}

const { mime } = req.query;

if (mime === undefined || !(typeof mime === 'string')) {
standardResponse(res, 400, false, '', {
error: {
name: 'INVALID_QUERY',
message: 'missing mime',
},
});
return;
}

this.userService
.getPresignedUrlMedia(req.params.mime)
.getPresignedUrlMedia(mime)
.then((r) => standardResponse(res, 201, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/routes/v2/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ export default (app: Router): void => {
/**
* @swagger
*
* /users/presigned/{mime}:
* /users/presigned:
* get:
* tags:
* - "users"
* summary: "Get AWS presigned URL to upload media content"
* parameters:
* - in: path
* - in: query
* name: mime
* schema:
* type: string
Expand All @@ -309,7 +309,7 @@ export default (app: Router): void => {
* - "write:modify":
*/
route.get(
'/presigned/:mime',
'/presigned/:query?',
authenticateToken,
userController.getPresignedUrlMedia
);
Expand Down