Skip to content

Commit 34dd2ff

Browse files
committed
Add first and last name to user creation
1 parent cf564ab commit 34dd2ff

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

backend/user-service/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PORT=3001
55
JWT_SECRET=you-can-replace-this-with-your-own-secret
66

77
# admin default credentials
8+
ADMIN_FIRST_NAME=Admin
9+
ADMIN_LAST_NAME=User
810
ADMIN_USERNAME=administrator
911
ADMIN_EMAIL=[email protected]
1012
ADMIN_PASSWORD=Admin@123

backend/user-service/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848

4949
- Body
5050

51-
- Required: `username` (string), `email` (string), `password` (string)
51+
- Required: `firstName` (string), `lastName` (string), `username` (string), `email` (string), `password` (string)
5252

5353
```json
5454
{
55+
"firstName": "SampleFirstName",
56+
"lastName": "SampleLastName",
5557
"username": "SampleUserName",
5658
"email": "[email protected]",
5759
"password": "SecurePassword"

backend/user-service/scripts/seed.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import { connectToDB, createUser, findUserByEmail } from "../model/repository";
44
export async function seedAdminAccount() {
55
await connectToDB();
66

7+
const adminFirstName = process.env.ADMIN_FIRST_NAME || "Admin";
8+
const adminLastName = process.env.ADMIN_LAST_NAME || "User";
79
const adminUsername = process.env.ADMIN_USERNAME || "administrator";
810
const adminEmail = process.env.ADMIN_EMAIL || "[email protected]";
911
const adminPassword = process.env.ADMIN_PASSWORD || "Admin@123";
1012

1113
if (
14+
!process.env.ADMIN_FIRST_NAME ||
15+
!process.env.ADMIN_LAST_NAME ||
1216
!process.env.ADMIN_USERNAME ||
1317
!process.env.ADMIN_EMAIL ||
1418
!process.env.ADMIN_PASSWORD
1519
) {
1620
console.error(
17-
"Admin account not seeded in .env. Using default admin account credentials (username: administrator, email: [email protected], password: Admin@123)"
21+
"Admin account not seeded in .env. Using default admin account credentials (first name: Admin, last name: User, username: administrator, email: [email protected], password: Admin@123)"
1822
);
1923
}
2024

@@ -28,7 +32,7 @@ export async function seedAdminAccount() {
2832
const salt = bcrypt.genSaltSync(10);
2933
const hashedPassword = bcrypt.hashSync(adminPassword, salt);
3034

31-
await createUser(adminUsername, adminEmail, hashedPassword, true);
35+
await createUser(adminFirstName, adminLastName, adminUsername, adminEmail, hashedPassword, true);
3236

3337
console.log("Admin account created successfully.");
3438
process.exit(0);

backend/user-service/swagger.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,23 @@ paths:
108108
content:
109109
application/json:
110110
schema:
111-
$ref: "#/components/schemas/User"
111+
type: object
112+
properties:
113+
firstName:
114+
type: string
115+
required: true
116+
lastName:
117+
type: string
118+
required: true
119+
username:
120+
type: string
121+
required: true
122+
email:
123+
type: string
124+
required: true
125+
password:
126+
type: string
127+
required: true
112128
responses:
113129
201:
114130
description: Successful Response
@@ -219,13 +235,13 @@ paths:
219235
application/json:
220236
schema:
221237
$ref: "#/components/schemas/ErrorResponse"
222-
404:
238+
404:
223239
description: Not Found
224240
content:
225241
application/json:
226242
schema:
227243
$ref: "#/components/schemas/ErrorResponse"
228-
500:
244+
500:
229245
description: Internal Server Error
230246
content:
231247
application/json:

0 commit comments

Comments
 (0)