Skip to content

Commit afeef43

Browse files
committed
feat: user upsert by email phone username
1 parent 45f36ea commit afeef43

File tree

2 files changed

+211
-6
lines changed

2 files changed

+211
-6
lines changed

openapi.json

Lines changed: 159 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"hash": "8fa4352badf47ee1a3486b4100f2e79f8f7fe294b54379d7af2067b8eef57d41",
2+
"hash": "818cd6240b28c9035aeceb5ae18bfc6270cb162b421a3326113b8d1d1a782d29",
33
"openapi": "3.0.0",
44
"paths": {
55
"/hello": {
@@ -778,9 +778,9 @@
778778
]
779779
}
780780
},
781-
"/users/{employeeId}/@upsertUserByEmployee": {
781+
"/users/{employeeId}/@upsertUserByEmployeeId": {
782782
"post": {
783-
"operationId": "upsertUserByEmployee",
783+
"operationId": "upsertUserByEmployeeId",
784784
"summary": "",
785785
"description": "Upsert user by employeeId",
786786
"parameters": [
@@ -830,6 +830,162 @@
830830
]
831831
}
832832
},
833+
"/users/{username}/@upsertUserByUsername": {
834+
"post": {
835+
"operationId": "upsertUserByUsername",
836+
"summary": "",
837+
"description": "Upsert user by username",
838+
"parameters": [
839+
{
840+
"name": "username",
841+
"required": true,
842+
"in": "path",
843+
"schema": {
844+
"type": "string"
845+
}
846+
}
847+
],
848+
"requestBody": {
849+
"required": true,
850+
"content": {
851+
"application/json": {
852+
"schema": {
853+
"$ref": "#/components/schemas/CreateUserDto"
854+
}
855+
}
856+
}
857+
},
858+
"responses": {
859+
"200": {
860+
"description": "The user upserted.",
861+
"content": {
862+
"application/json": {
863+
"schema": {
864+
"$ref": "#/components/schemas/User"
865+
}
866+
}
867+
}
868+
},
869+
"201": {
870+
"description": "",
871+
"content": {
872+
"application/json": {
873+
"schema": {
874+
"type": "object"
875+
}
876+
}
877+
}
878+
}
879+
},
880+
"tags": [
881+
"user"
882+
]
883+
}
884+
},
885+
"/users/{email}/@upsertUserByEmail": {
886+
"post": {
887+
"operationId": "upsertUserByEmail",
888+
"summary": "",
889+
"description": "Upsert user by email",
890+
"parameters": [
891+
{
892+
"name": "email",
893+
"required": true,
894+
"in": "path",
895+
"schema": {
896+
"type": "string"
897+
}
898+
}
899+
],
900+
"requestBody": {
901+
"required": true,
902+
"content": {
903+
"application/json": {
904+
"schema": {
905+
"$ref": "#/components/schemas/CreateUserDto"
906+
}
907+
}
908+
}
909+
},
910+
"responses": {
911+
"200": {
912+
"description": "The user upserted.",
913+
"content": {
914+
"application/json": {
915+
"schema": {
916+
"$ref": "#/components/schemas/User"
917+
}
918+
}
919+
}
920+
},
921+
"201": {
922+
"description": "",
923+
"content": {
924+
"application/json": {
925+
"schema": {
926+
"type": "object"
927+
}
928+
}
929+
}
930+
}
931+
},
932+
"tags": [
933+
"user"
934+
]
935+
}
936+
},
937+
"/users/{phone}/@upsertUserByPhone": {
938+
"post": {
939+
"operationId": "upsertUserByPhone",
940+
"summary": "",
941+
"description": "Upsert user by phone",
942+
"parameters": [
943+
{
944+
"name": "phone",
945+
"required": true,
946+
"in": "path",
947+
"schema": {
948+
"type": "string"
949+
}
950+
}
951+
],
952+
"requestBody": {
953+
"required": true,
954+
"content": {
955+
"application/json": {
956+
"schema": {
957+
"$ref": "#/components/schemas/CreateUserDto"
958+
}
959+
}
960+
}
961+
},
962+
"responses": {
963+
"200": {
964+
"description": "The user upserted.",
965+
"content": {
966+
"application/json": {
967+
"schema": {
968+
"$ref": "#/components/schemas/User"
969+
}
970+
}
971+
}
972+
},
973+
"201": {
974+
"description": "",
975+
"content": {
976+
"application/json": {
977+
"schema": {
978+
"type": "object"
979+
}
980+
}
981+
}
982+
}
983+
},
984+
"tags": [
985+
"user"
986+
]
987+
}
988+
},
833989
"/users/{userId}/@verifyIdentity": {
834990
"post": {
835991
"operationId": "verifyIdentity",

src/user/user.controller.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ export class UserController {
283283
/**
284284
* Upsert user by employeeId
285285
*/
286-
@ApiOperation({ operationId: 'upsertUserByEmployee' })
286+
@ApiOperation({ operationId: 'upsertUserByEmployeeId' })
287287
@ApiOkResponse({
288288
description: 'The user upserted.',
289289
type: User,
290290
})
291-
@Post(':employeeId/@upsertUserByEmployee')
292-
async upsert(
291+
@Post(':employeeId/@upsertUserByEmployeeId')
292+
async upsertByEmployeeId(
293293
@Param('employeeId') employeeId: string,
294294
@Body() dto: CreateUserDto
295295
): Promise<UserDocument> {
@@ -379,6 +379,55 @@ export class UserController {
379379
return this.userService.upsertByEmployee(employeeId, dto);
380380
}
381381

382+
/**
383+
* Upsert user by username
384+
*/
385+
@ApiOperation({ operationId: 'upsertUserByUsername' })
386+
@ApiOkResponse({
387+
description: 'The user upserted.',
388+
type: User,
389+
})
390+
@Post(':username/@upsertUserByUsername')
391+
async upsertByUsername(
392+
@Param('username') username: string,
393+
@Body() dto: CreateUserDto
394+
): Promise<UserDocument> {
395+
// TODO: 从返回的数据库错误中,解析数据冲突的字段
396+
return this.userService.upsertByUsername(username, dto);
397+
}
398+
399+
/**
400+
* Upsert user by email
401+
*/
402+
@ApiOperation({ operationId: 'upsertUserByEmail' })
403+
@ApiOkResponse({
404+
description: 'The user upserted.',
405+
type: User,
406+
})
407+
@Post(':email/@upsertUserByEmail')
408+
async upsertByEmail(
409+
@Param('email') email: string,
410+
@Body() dto: CreateUserDto
411+
): Promise<UserDocument> {
412+
return this.userService.upsertByEmail(email, dto);
413+
}
414+
415+
/**
416+
* Upsert user by phone
417+
*/
418+
@ApiOperation({ operationId: 'upsertUserByPhone' })
419+
@ApiOkResponse({
420+
description: 'The user upserted.',
421+
type: User,
422+
})
423+
@Post(':phone/@upsertUserByPhone')
424+
async upsertByPhone(
425+
@Param('phone') phone: string,
426+
@Body() dto: CreateUserDto
427+
): Promise<UserDocument> {
428+
return this.userService.upsertByPhone(phone, dto);
429+
}
430+
382431
/**
383432
* Delete user
384433
*/

0 commit comments

Comments
 (0)