Skip to content

Commit

Permalink
Merge pull request #29 from Finboost/dev-arman
Browse files Browse the repository at this point in the history
feat: update db schema, seeder, docs, and api for user profile
  • Loading branch information
armandwipangestu authored Jun 15, 2024
2 parents b465fba + 6cbbef1 commit 631c41c
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 5 deletions.
60 changes: 57 additions & 3 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@
"data": {
"profile": {
"id": "de5b1599-b1b7-4633-8a5d-331690ee9413",
"about": "Sophismata tum crur tabgo angulus. Certe statua adfero statua talis aveho aspicio. Pel voluptatum strenuus.",
"avatar": "https://storage.googleapis.com/finboost/example.png",
"maritalStatus": "Lajang",
"certifiedStatus": null,
Expand All @@ -1154,7 +1155,12 @@
"education": {
"id": "7fe46a1f-fb32-4e36-9741-d96f22cf4b4b",
"name": "SMA / Sederajat"
}
},
"investment": "Saham",
"insurance": "Obligasi",
"incomePerMonth": "9211156",
"totalSaving": "111138960",
"totalDebt": "10000000"
}
}
}
Expand All @@ -1167,6 +1173,7 @@
"data": {
"profile": {
"id": "36429cef-96d1-41a7-b579-c2dc8d4f2beb",
"about": null,
"avatar": "https://storage.googleapis.com/finboost/example2.png",
"maritalStatus": "Menikah",
"certifiedStatus": "Certified Financial Planner",
Expand All @@ -1177,7 +1184,12 @@
"education": {
"id": "b5fbeaee-812f-4ec3-b807-22dd2794e09a",
"name": "S1"
}
},
"investment": null,
"insurance": null,
"incomePerMonth": null,
"totalSaving": null,
"totalDebt": null
}
}
}
Expand Down Expand Up @@ -1225,10 +1237,16 @@
"User 1": {
"description": "Example request to partially update user profile",
"value": {
"about": "Testing About",
"maritalStatus": "Lajang",
"certifiedStatus": null,
"workId": "319defd8-1836-4b9d-af2d-655a43a60bde",
"educationId": "7fe46a1f-fb32-4e36-9741-d96f22cf4b4b"
"educationId": "7fe46a1f-fb32-4e36-9741-d96f22cf4b4b",
"investment": "Saham",
"insurance": "Obligasi",
"incomePerMonth": "2400000",
"totalSaving": "5000000",
"totalDebt": "10000000"
}
},
"User 2": {
Expand Down Expand Up @@ -3343,6 +3361,9 @@
"id": {
"type": "string"
},
"about": {
"type": "string"
},
"avatar": {
"type": "string"
},
Expand All @@ -3357,6 +3378,21 @@
},
"educationId": {
"type": "string"
},
"investment": {
"type": "string"
},
"insurance": {
"type": "string"
},
"incomePerMonth": {
"type": "string"
},
"totalSaving": {
"type": "string"
},
"totalDebt": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -3424,6 +3460,9 @@
"UpdatePartialFieldProfile": {
"type": "object",
"properties": {
"about": {
"type": "string"
},
"maritalStatus": {
"type": "string"
},
Expand All @@ -3435,6 +3474,21 @@
},
"educationId": {
"type": "string"
},
"investment": {
"type": "string"
},
"insurance": {
"type": "string"
},
"incomePerMonth": {
"type": "string"
},
"totalSaving": {
"type": "string"
},
"totalDebt": {
"type": "string"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE `profiles` ADD COLUMN `incomePerMonth` INTEGER NULL,
ADD COLUMN `insurance` ENUM('Saham', 'Reksadana', 'Obligasi', 'Emas', 'Cryptocurrency') NULL,
ADD COLUMN `investment` ENUM('Saham', 'Reksadana', 'Obligasi', 'Emas', 'Cryptocurrency') NULL,
ADD COLUMN `totalDebt` INTEGER NULL,
ADD COLUMN `totalSaving` INTEGER NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `profiles` ADD COLUMN `about` VARCHAR(191) NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE `profiles` MODIFY `incomePerMonth` BIGINT NULL,
MODIFY `totalDebt` BIGINT NULL,
MODIFY `totalSaving` BIGINT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE `profiles` MODIFY `incomePerMonth` DECIMAL(65, 30) NULL,
MODIFY `totalDebt` DECIMAL(65, 30) NULL,
MODIFY `totalSaving` DECIMAL(65, 30) NULL;
12 changes: 12 additions & 0 deletions prisma/migrations/20240615105605_formatting_decimal/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- You are about to alter the column `incomePerMonth` on the `profiles` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(25,2)`.
- You are about to alter the column `totalDebt` on the `profiles` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(25,2)`.
- You are about to alter the column `totalSaving` on the `profiles` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(25,2)`.
*/
-- AlterTable
ALTER TABLE `profiles` MODIFY `incomePerMonth` DECIMAL(25, 2) NULL,
MODIFY `totalDebt` DECIMAL(25, 2) NULL,
MODIFY `totalSaving` DECIMAL(25, 2) NULL;
17 changes: 16 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ model User {
profile Profile?
UserChatRoom ChatRoom[] @relation("UserChatRoom")
UserChatRoom ChatRoom[] @relation("UserChatRoom")
ExpertChatRoom ChatRoom[] @relation("ExpertChatRoom")
@@map("users")
Expand All @@ -51,6 +51,7 @@ model Role {
model Profile {
id String @id @default(uuid())
avatar String?
about String?
maritalStatus ProfileMarital?
certifiedStatus String?
createdAt DateTime @default(now())
Expand All @@ -62,6 +63,12 @@ model Profile {
education Education? @relation(fields: [educationId], references: [id])
educationId String?
investment ProfileInvestmentAndInsurance?
insurance ProfileInvestmentAndInsurance?
incomePerMonth Decimal? @db.Decimal(25, 2)
totalSaving Decimal? @db.Decimal(25, 2)
totalDebt Decimal? @db.Decimal(25, 2)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique
Expand Down Expand Up @@ -117,6 +124,14 @@ enum ProfileMarital {
Cerai
}

enum ProfileInvestmentAndInsurance {
Saham
Reksadana
Obligasi
Emas
Cryptocurrency
}

enum ChatRoomType {
Expert
AI
Expand Down
47 changes: 46 additions & 1 deletion prisma/seed/users.seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const seedUsers = async (count) => {
"Laki_laki",
"Perempuan",
]);
const age = faker.datatype.number({ min: 18, max: 80 });
const age = faker.number.int({ min: 18, max: 80 });
const phoneNumber = faker.phone.number();
const password = hashPassword;
const avatarDefault =
gender === "Laki_laki"
? getPublicUrl("male.png")
: getPublicUrl("female.png");
const about = faker.lorem.paragraph(1);

const maritalStatus = faker.helpers.arrayElement([
"Lajang",
Expand All @@ -47,6 +48,37 @@ const seedUsers = async (count) => {
const randomWork = works[Math.floor(Math.random() * works.length)];
const workId = randomWork.id;

const investment = faker.helpers.arrayElement([
"Saham",
"Reksadana",
"Obligasi",
"Emas",
"Cryptocurrency",
]);

const insurance = faker.helpers.arrayElement([
"Saham",
"Reksadana",
"Obligasi",
"Emas",
"Cryptocurrency",
]);

const incomePerMonth = faker.number.int({
min: 0,
max: 25000000,
});

const totalSaving = faker.number.int({
min: 0,
max: 144000000,
});

const totalDebt = faker.number.int({
min: 0,
max: 144000000,
});

await prisma.user.create({
data: {
fullName,
Expand All @@ -59,6 +91,7 @@ const seedUsers = async (count) => {
profile: {
create: {
avatar: avatarDefault,
about,
maritalStatus,
certifiedStatus:
randomRole.name === "Expert"
Expand All @@ -74,6 +107,18 @@ const seedUsers = async (count) => {
id: educationId,
},
},
investment:
randomRole.name === "User" ? investment : null,
insurance:
randomRole.name === "User" ? insurance : null,
incomePerMonth:
randomRole.name === "User"
? incomePerMonth
: null,
totalSaving:
randomRole.name === "User" ? totalSaving : null,
totalDebt:
randomRole.name === "User" ? totalDebt : null,
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions src/controller/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getFileNameFromUrl,
getPublicUrl,
} from "../utils/bucket.util.js";
import { Decimal } from "@prisma/client/runtime/library";

export const getAllUsersHandler = async (req, res) => {
try {
Expand Down Expand Up @@ -153,6 +154,18 @@ export const editUserProfilePartialFieldByUserIdHandler = async (req, res) => {
req.body
);

if (req.body.incomePerMonth) {
req.body.incomePerMonth = new Decimal(req.body.incomePerMonth);
}

if (req.body.totalSaving) {
req.body.totalSaving = new Decimal(req.body.totalSaving);
}

if (req.body.totalDebt) {
req.body.totalDebt = new Decimal(req.body.totalDebt);
}

const user = await editUserProfileByUserId(userId, validateData, res);

res.status(200).send({
Expand Down
Loading

0 comments on commit 631c41c

Please sign in to comment.