Skip to content

Commit

Permalink
Merge pull request #27 from purwadhikafullstack/develop
Browse files Browse the repository at this point in the history
Merge develop to main
  • Loading branch information
danielreinhard1129 authored Oct 12, 2024
2 parents 1295d0e + 9050e8d commit 6442917
Show file tree
Hide file tree
Showing 204 changed files with 12,923 additions and 977 deletions.
5 changes: 4 additions & 1 deletion apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
# GMAIL_APP_PASSWORD=
# CLOUDINARY_API_KEY=
# CLOUDINARY_API_SECRET=
# CLOUDINARY_CLOUD_NAME=
# CLOUDINARY_CLOUD_NAME=
# MIDTRANS_MERCHANT_ID=
# MIDTRANS_CLIENT_KEY=
# MIDTRANS_SERVER-KEY=
3 changes: 3 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"express-validator": "^7.2.0",
"handlebars": "^4.7.8",
"jsonwebtoken": "^9.0.2",
"midtrans-node-client": "^0.0.6",
"multer": "^1.4.5-lts.1",
"node-schedule": "^2.1.1",
"nodemailer": "^6.9.15",
"streamifier": "^0.1.1",
"ts-node": "^10.9.2",
Expand All @@ -36,6 +38,7 @@
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"@types/multer": "^1.4.12",
"@types/node-schedule": "^2.1.7",
"@types/nodemailer": "^6.4.15",
"@types/streamifier": "^0.1.2",
"prisma": "^5.7.1",
Expand Down
44 changes: 31 additions & 13 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ model Outlet {
id Int @id @default(autoincrement())
name String @unique
type Type
address String?
latitude String
longitude String
isDeleted Boolean @default(false)
Expand All @@ -90,6 +91,7 @@ model Outlet {
orders Order[]
pickupOrders Pickup_Order[]
deliveryOrders Delivery_Order[]
workOrders Work_Order[]
@@map("outlets")
}
Expand Down Expand Up @@ -188,16 +190,19 @@ model LaundryItem {
}

model Payment {
id Int @id @default(autoincrement())
invoiceNumber Int @unique
paymentMethod String
paymentProof String
status PaymentStatus
isDeleted Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
order Order @relation(fields: [orderId], references: [id])
orderId Int
id Int @id @default(autoincrement())
invoiceNumber String @unique
amount Int
paymentMethod String?
paymentProof String?
status PaymentStatus @default(PENDING)
snapToken String?
snapRedirectUrl String?
isDeleted Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
order Order @relation(fields: [orderId], references: [id])
orderId Int
@@map("payments")
}
Expand Down Expand Up @@ -271,22 +276,35 @@ enum PickupStatus {
model Work_Order {
id Int @id @default(autoincrement())
status WorkStatus
byPassedAdmin Int
byPassed Boolean @default(false)
byPassedAdmin Int?
bypassNote String?
isDeleted Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
order Order @relation(fields: [orderId], references: [id])
orderId Int
employee Employee @relation(fields: [employeeId], references: [id])
employeeId Int
employeeId Int @default(1)
station Station @relation(fields: [stationId], references: [id])
stationId Int
outlet Outlet @relation(fields: [outletId], references: [id])
outletId Int
@@map("work_orders")
}

enum WorkStatus {
m
READY_FOR_WASHING
BEING_WASHED
WASHING_COMPLETED
READY_FOR_IRONING
BEING_IRONED
IRONING_COMPLETED
READY_FOR_PACKING
BEING_PACKED
PACKING_COMPLETED
BYPASSED
}

model Station {
Expand Down
12 changes: 12 additions & 0 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { PickupRouter } from './routers/pickup.router';
import { OutletRouter } from './routers/outlet.router';
import { NotificationRouter } from './routers/notification.router';
import { LaundryItemRouter } from './routers/laundry-item.router';
import { WorkRouter } from './routers/work.router';
import { OrderItemRouter } from './routers/order-item.router';
import { PaymentRouter } from './routers/payment.router';
import { DeliveryRouter } from './routers/delivery.router';

export default class App {
private app: Express;
Expand Down Expand Up @@ -69,6 +73,10 @@ export default class App {
const outletRouter = new OutletRouter();
const notificationRouter = new NotificationRouter();
const laundryItemRouter = new LaundryItemRouter();
const workRouter = new WorkRouter();
const orderItemRouter = new OrderItemRouter();
const paymentRouter = new PaymentRouter();
const deliveryRouter = new DeliveryRouter();

this.app.get('/api', (req: Request, res: Response) => {
res.send(`Hello, Purwadhika Student API!`);
Expand All @@ -84,6 +92,10 @@ export default class App {
this.app.use('/api/outlets', outletRouter.getRouter());
this.app.use('/api/notifications', notificationRouter.getRouter());
this.app.use('/api/laundry-items', laundryItemRouter.getRouter());
this.app.use('/api/work-orders', workRouter.getRouter());
this.app.use('/api/order-items', orderItemRouter.getRouter());
this.app.use('/api/payments', paymentRouter.getRouter());
this.app.use('/api/delivery-orders', deliveryRouter.getRouter());
}

public start(): void {
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export const GMAIL_APP_PASSWORD = process.env.GMAIL_APP_PASSWORD;
export const CLOUDINARY_API_KEY = process.env.CLOUDINARY_API_KEY;
export const CLOUDINARY_API_SECRET = process.env.CLOUDINARY_API_SECRET;
export const CLOUDINARY_CLOUD_NAME = process.env.CLOUDINARY_CLOUD_NAME;
export const MIDTRANS_MERCHANT_ID = process.env.MIDTRANS_MERCHANT_ID;
export const MIDTRANS_CLIENT_KEY = process.env.MIDTRANS_CLIENT_KEY;
export const MIDTRANS_SERVER_KEY = process.env.MIDTRANS_SERVER_KEY;
36 changes: 35 additions & 1 deletion apps/api/src/controllers/admin.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createUserService } from '@/services/admin/create-user.service';
import { deleteUserService } from '@/services/admin/delete-user.service';
import { getCustomersService } from '@/services/admin/get-customers.service';
import { getEmployeeService } from '@/services/admin/get-employee.service';
import { getEmployeesService } from '@/services/admin/get-employees.service';
import { getUserAdminService } from '@/services/admin/get-user-admin.service';
import { updateUserService } from '@/services/admin/update-user.service';
import { Role } from '@prisma/client';
import { NextFunction, Request, Response } from 'express';

Expand Down Expand Up @@ -49,9 +52,40 @@ export class AdminController {
}
}

async getEmployeeAdmin(req: Request, res: Response, next: NextFunction) {
try {
const result = await getEmployeeService(Number(req.params.id));
return res.status(200).send(result);
} catch (error) {
next(error);
}
}
async createUserAdmin(req: Request, res: Response, next: NextFunction) {
try {
const result = await createUserService(req.body);
const result = await createUserService(req.body, req.file!);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async updateEmployeeAdmin(req: Request, res: Response, next: NextFunction) {
try {
const result = await updateUserService(
Number(req.params.id),
req.body,
req.file!,
);

return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async deleteUserAdmin(req: Request, res: Response, next: NextFunction) {
try {
const result = await deleteUserService(req.body);
return res.status(200).send(result);
} catch (error) {
next(error);
Expand Down
77 changes: 77 additions & 0 deletions apps/api/src/controllers/delivery.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { getDeliveryUserService } from "@/services/delivery/get-deliver-user.service";
import { getDeliveryAdminsService } from "@/services/delivery/get-delivery-admins.service";
import { getDeliveryDriverService } from "@/services/delivery/get-delivery-driver.service";
import { updateDeliveryOrderDriverService } from "@/services/delivery/update-deliver.service";
import { NextFunction, Request, Response } from 'express';


export class DeliveryController {

async getDeliveryOrdersDrivers(req: Request, res: Response, next: NextFunction) {
try {
const query = {
page: parseInt(req.query.page as string) || 1,
take: parseInt(req.query.take as string) || 3,
sortOrder: (req.query.sortOrder as string) || 'asc',
sortBy: (req.query.sortBy as string) || 'createdAt',
search: (req.query.search as string) || '',
status: (req.query.status as 'ONGOING' | 'REQUEST' | 'HISTORY'),
};

const result = await getDeliveryDriverService(query, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async getDeliveryOrdersAdmins(req: Request, res: Response, next: NextFunction) {
try {
const query = {
page: parseInt(req.query.page as string) || 1,
take: parseInt(req.query.take as string) || 5,
sortOrder: (req.query.sortOrder as string) || 'asc',
sortBy: (req.query.sortBy as string) || 'createdAt',
search: (req.query.search as string) || '',
status: (req.query.status as 'ONGOING' | 'REQUEST' | 'HISTORY' | 'ALL') || 'ALL',
outletId: (req.query.outletId as string) || '',
};

const result = await getDeliveryAdminsService(query, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async getDeliveryOrdersUser(req: Request, res: Response, next: NextFunction) {
try {
const query = {
page: parseInt(req.query.page as string) || 1,
take: parseInt(req.query.take as string) || 3,
sortOrder: (req.query.sortOrder as string) || 'asc',
sortBy: (req.query.sortBy as string) || 'createdAt',
search: (req.query.search as string) || '',
status: (req.query.status as 'ONGOING' | 'HISTORY' | 'ALL'),
};

const result = await getDeliveryUserService(query, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async updateDeliveryDriver(
req: Request,
res: Response,
next: NextFunction,
) {
try {
const result = await updateDeliveryOrderDriverService(req.body, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}
}
20 changes: 20 additions & 0 deletions apps/api/src/controllers/order-item.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getOrderItemsWorkOrderService } from '@/services/order-item/get-order-items.service';
import { NextFunction, Request, Response } from 'express';

export class OrderItemController {
async getOrderItemsWorkOrder(req: Request, res: Response, next: NextFunction) {
try {
const query = {
page: parseInt(req.query.page as string) || 1,
take: parseInt(req.query.take as string) || 3,
sortOrder: (req.query.sortOrder as string) || 'desc',
sortBy: (req.query.sortBy as string) || 'createdAt',
workOrderId: parseInt(req.query.workOrderId as string) || 0,
};
const result = await getOrderItemsWorkOrderService(query);
res.status(200).send(result);
} catch (error) {
next(error);
}
}
}
43 changes: 42 additions & 1 deletion apps/api/src/controllers/order.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createUserOrderService } from '@/services/order/create-user-order.service';
import { getOrderUserService } from '@/services/order/get-order-user.service';
import { getOrdersOutletService } from '@/services/order/get-orders-outlet.service';
import { getOrdersUserService } from '@/services/order/get-orders-user.service';
import { getOrdersService } from '@/services/order/get-orders.service';
import { processOrderService } from '@/services/order/process-order.service';
import { createPickupService } from '@/services/pickup/create-pickup.service';
import { OrderStatus } from '@prisma/client';
import { NextFunction, Request, Response } from 'express';
Expand Down Expand Up @@ -43,7 +46,7 @@ export class OrderController {
sortOrder: (req.query.sortOrder as string) || 'asc',
sortBy: (req.query.sortBy as string) || 'createdAt',
search: (req.query.search as string) || '',
status: (req.query.status as OrderStatus) || "",
status: (req.query.status as OrderStatus) || "ALL",
outletId: Number(req.query.outletId as string) || 0,
};

Expand All @@ -53,4 +56,42 @@ export class OrderController {
next(error);
}
}

async processOrder(req: Request, res: Response, next: NextFunction) {
try {
const result = await processOrderService(req.body, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async getOrdersUser(req: Request, res: Response, next: NextFunction) {
try {
const query = {
page: parseInt(req.query.page as string) || 1,
take: parseInt(req.query.take as string) || 3,
sortOrder: (req.query.sortOrder as string) || 'asc',
sortBy: (req.query.sortBy as string) || 'createdAt',
search: (req.query.search as string) || '',
status: (req.query.status as OrderStatus) || "",
outletId: Number(req.query.outletId as string) || 0,
isPaid: (req.query.isPaid as string) || '',
};

const result = await getOrdersUserService(query, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async getOrderUser(req: Request, res: Response, next: NextFunction) {
try {
const result = await getOrderUserService(Number(req.params.id), res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}
}
23 changes: 23 additions & 0 deletions apps/api/src/controllers/payment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { processPaymentService } from '@/services/payment/process-payment.service';
import { updatePaymentSuccessService } from '@/services/payment/update-payment-succes.service';
import { NextFunction, Request, Response } from 'express';

export class PaymentController {
async processPayment(req: Request, res: Response, next: NextFunction) {
try {
const result = await processPaymentService(req.body, res.locals.user.id);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

async updatePaymentSuccess(req: Request, res: Response, next: NextFunction) {
try {
const result = await updatePaymentSuccessService(req.body);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}
}
Loading

0 comments on commit 6442917

Please sign in to comment.