Merge pull request #37 from internship-humic/feat/limit-update-nama-interns

feat: limit update nama untuk user intern maksimal sekali
This commit is contained in:
Muhammad Zhafran Ilham
2026-07-13 18:03:23 +07:00
committed by GitHub
4 changed files with 226 additions and 27 deletions
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `user` ADD COLUMN `changes` INTEGER NOT NULL DEFAULT 0;
+1
View File
@@ -189,6 +189,7 @@ model User {
professional_bio String? @db.Text
intern_position String? @db.VarChar(255)
intern_interest_group String? @db.VarChar(255)
changes Int @default(0)
is_active Boolean @default(true)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
+19 -1
View File
@@ -244,7 +244,25 @@ class AuthService {
}
const updateData = {};
if (full_name) updateData.full_name = full_name;
if (full_name !== undefined) {
const nextFullName = full_name.trim();
const currentFullName = existingUser.full_name?.trim();
if (!nextFullName) {
return error(new BadRequestError('Nama lengkap tidak boleh kosong'));
}
if (nextFullName !== currentFullName) {
if (existingUser.changes >= 1) {
return error(new ConflictError('Nama hanya dapat diubah satu kali'));
}
updateData.full_name = nextFullName;
updateData.changes = {
increment: 1,
};
}
}
if (email) updateData.email = email;
if (hashedPassword) updateData.password = hashedPassword;
if (professional_bio !== undefined) updateData.professional_bio = professional_bio;
+192 -14
View File
@@ -50,45 +50,223 @@ router.post("/login", authController.login);
* @swagger
* /auth-api/me:
* get:
* summary: Get authenticated admin details
* summary: Get authenticated user details
* description: Retrieve the currently authenticated user profile. Response data depends on the authenticated user's role.
* tags: [Auth]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: Get admin details successfully
* description: Get authenticated user details successfully
* content:
* application/json:
* schema:
* type: object
* oneOf:
* - type: object
* properties:
* message:
* type: string
* example: "Get admin successfully"
* status:
* type: boolean
* example: true
* data:
* type: object
* description: Intern profile data
* properties:
* id:
* type: integer
* example: 1
* id_mahasiswa:
* type: integer
* nullable: true
* example: 1
* id_lamaran_magang:
* type: integer
* nullable: true
* example: 1
* full_name:
* type: string
* example: "Rafi Athallah"
* email:
* type: string
* example: "rafi@student.com"
* role:
* type: string
* example: "intern"
* professional_bio:
* type: string
* nullable: true
* example: null
* intern_position:
* type: string
* nullable: true
* example: null
* intern_interest_group:
* type: string
* nullable: true
* example: null
* changes:
* type: integer
* example: 0
* description: Number of times the intern has changed their full name.
* is_active:
* type: boolean
* example: true
* created_at:
* type: string
* format: date-time
* example: "2026-07-10T22:45:24.305Z"
* updated_at:
* type: string
* format: date-time
* example: "2026-07-10T22:45:24.305Z"
* lamaran_magang:
* type: object
* nullable: true
* properties:
* id:
* type: integer
* example: 1
* id_mahasiswa:
* type: integer
* example: 1
* id_lowongan_magang:
* type: string
* example: "LOW-001"
* status:
* type: string
* example: "diterima"
* batch:
* type: integer
* example: 3
* created_at:
* type: string
* format: date-time
* example: "2026-07-10T22:45:24.186Z"
* update_at:
* type: string
* format: date-time
* example: "2026-07-10T22:45:24.185Z"
* lowongan_magang:
* type: object
* nullable: true
* properties:
* posisi:
* type: string
* example: "Web Developer"
* kelompok_peminatan:
* type: string
* example: "Software Engineering"
* position:
* type: string
* nullable: true
* example: "Web Developer"
* kelompok_peminatan:
* type: string
* nullable: true
* example: "Software Engineering"
* message:
* type: string
* example: "Pengguna berhasil diambil"
* code:
* type: integer
* example: 200
* - type: object
* properties:
* status:
* type: boolean
* example: true
* data:
* type: object
* description: Admin or mentor profile data
* properties:
* id:
* type: integer
* example: 1
* nama_depan:
* type: string
* example: "John"
* example: "Admin"
* nama_belakang:
* type: string
* example: "Doe"
* email:
* type: string
* example: "admin@example.com"
* nullable: true
* example: "One"
* role:
* type: string
* example: "admin"
* email:
* type: string
* example: "admin1@internify.com"
* signature:
* type: string
* nullable: true
* example: "Admin-One-1783723523926"
* profile_picture:
* type: string
* nullable: true
* example: "https://placehold.co/150"
* professional_bio:
* type: string
* nullable: true
* example: "Senior Program Manager at Internify."
* message:
* type: string
* example: "Pengguna berhasil diambil"
* code:
* type: integer
* example: 200
* examples:
* intern:
* summary: Intern response
* value:
* status: true
* data:
* id: 1
* id_mahasiswa: 1
* id_lamaran_magang: 1
* full_name: "Rafi Athallah"
* email: "rafi@student.com"
* role: "intern"
* professional_bio: null
* intern_position: null
* intern_interest_group: null
* changes: 0
* is_active: true
* created_at: "2026-07-10T22:45:24.305Z"
* updated_at: "2026-07-10T22:45:24.305Z"
* lamaran_magang:
* id: 1
* id_mahasiswa: 1
* id_lowongan_magang: "LOW-001"
* status: "diterima"
* batch: 3
* created_at: "2026-07-10T22:45:24.186Z"
* update_at: "2026-07-10T22:45:24.185Z"
* lowongan_magang:
* posisi: "Web Developer"
* kelompok_peminatan: "Software Engineering"
* position: "Web Developer"
* kelompok_peminatan: "Software Engineering"
* message: "Pengguna berhasil diambil"
* code: 200
* admin:
* summary: Admin response
* value:
* status: true
* data:
* id: 1
* nama_depan: "Admin"
* nama_belakang: "One"
* role: "admin"
* email: "admin1@internify.com"
* signature: "Admin-One-1783723523926"
* profile_picture: "https://placehold.co/150"
* professional_bio: "Senior Program Manager at Internify."
* message: "Pengguna berhasil diambil"
* code: 200
* 401:
* description: Authorization header missing or invalid
* 403:
* description: Invalid or expired token
* 404:
* description: Admin not found
* description: User not found
* 500:
* description: Internal server error
*/
@@ -99,7 +277,7 @@ router.get("/me", verifyJWT, authController.me);
* /auth-api/update-profile:
* patch:
* summary: Update authenticated user profile
* description: Update profile details (full name, email, password, professional bio). Admins can also upload a profile picture.
* description: Update profile details (full name, email, password, professional bio). Admins can also upload a profile picture. Interns can only change full_name once.
* tags: [Auth]
* security:
* - bearerAuth: []
@@ -136,7 +314,7 @@ router.get("/me", verifyJWT, authController.me);
* 403:
* description: Forbidden (Interns uploading images)
* 409:
* description: Conflict (Email already in use)
* description: Conflict. Email already in use or intern has already changed full name once.
* 500:
* description: Internal server error
*/