yes
This commit is contained in:
parent
085de41194
commit
eb5e4f25a1
24 changed files with 1233 additions and 202 deletions
|
|
@ -8,6 +8,114 @@
|
|||
"schemas": {}
|
||||
},
|
||||
"paths": {
|
||||
"/api/user/changeDisplayName": {
|
||||
"put": {
|
||||
"operationId": "changeDisplayName",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "New Display Name"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"success"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"changeDisplayName.success"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"failure"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"changeDisplayName.alreadyExist",
|
||||
"changeDisplayName.invalid"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"notLoggedIn"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"auth.noCookie",
|
||||
"auth.invalidKind",
|
||||
"auth.noUser",
|
||||
"auth.invalid"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/user/info/{user}": {
|
||||
"get": {
|
||||
"operationId": "getUser",
|
||||
|
|
|
|||
44
src/user/src/routes/changeDisplayName.ts
Normal file
44
src/user/src/routes/changeDisplayName.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { FastifyPluginAsync } from 'fastify';
|
||||
|
||||
import { Static, Type } from 'typebox';
|
||||
import { isNullish, MakeStaticResponse, typeResponse } from '@shared/utils';
|
||||
|
||||
|
||||
export const ChangeDisplayNameRes = {
|
||||
'200': typeResponse('success', 'changeDisplayName.success'),
|
||||
'400': typeResponse('failure', ['changeDisplayName.alreadyExist', 'changeDisplayName.invalid']),
|
||||
};
|
||||
|
||||
export type ChangeDisplayNameRes = MakeStaticResponse<typeof ChangeDisplayNameRes>;
|
||||
|
||||
export const ChangeDisplayNameReq = Type.Object({ name: Type.String({ description: 'New Display Name' }) });
|
||||
type ChangeDisplayNameReq = Static<typeof ChangeDisplayNameReq>;
|
||||
|
||||
const USERNAME_CHECK: RegExp = /^[a-zA-Z_0-9]+$/;
|
||||
const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
||||
void _opts;
|
||||
fastify.put<{ Body: ChangeDisplayNameReq }>(
|
||||
'/api/user/changeDisplayName',
|
||||
{ schema: { body: ChangeDisplayNameReq, response: ChangeDisplayNameRes, operationId: 'changeDisplayName' }, config: { requireAuth: true } },
|
||||
async function(req, res) {
|
||||
if (isNullish(req.authUser)) return;
|
||||
if (isNullish(req.body.name)) {
|
||||
return res.makeResponse(400, 'failure', 'changeDisplayName.invalid');
|
||||
}
|
||||
if (req.body.name.length < 4 || req.body.name.length > 32) {
|
||||
return res.makeResponse(400, 'failure', 'changeDisplayName.invalid');
|
||||
}
|
||||
if (!USERNAME_CHECK.test(req.body.name)) {
|
||||
return res.makeResponse(400, 'failure', 'changeDisplayName.invalid');
|
||||
}
|
||||
if (this.db.updateDisplayName(req.authUser.id, req.body.name)) {
|
||||
return res.makeResponse(200, 'success', 'changeDisplayName.success');
|
||||
}
|
||||
else {
|
||||
return res.makeResponse(400, 'failure', 'changeDisplayName.alreadyExist');
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export default route;
|
||||
|
|
@ -49,7 +49,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
|||
if (isNullish(user)) {
|
||||
return res.makeResponse(404, 'failure', 'userinfo.failure.unknownUser');
|
||||
}
|
||||
|
||||
console.log(user);
|
||||
|
||||
const payload = {
|
||||
name: user.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue