Skip to content
Snippets Groups Projects
Commit 1ec3d2f6 authored by Kinanti Wening Asih's avatar Kinanti Wening Asih
Browse files

:star2:FEAT : Added Backend for Student, Schedule, Ins

parent 29883928
No related merge requests found
/*
Warnings:
- You are about to drop the column `umurSiswaa` on the `Student` table. All the data in the column will be lost.
- Added the required column `umurSiswa` to the `Student` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Schedule" ALTER COLUMN "jamMulai" SET DATA TYPE TIME,
ALTER COLUMN "jamSelesai" SET DATA TYPE TIME;
-- AlterTable
ALTER TABLE "Student" DROP COLUMN "umurSiswaa",
ADD COLUMN "umurSiswa" INTEGER NOT NULL;
......@@ -21,7 +21,7 @@ model Student {
idStudent Int @id @default(autoincrement())
namaSiswa String
kelasSiswa Int
umurSiswaa Int
umurSiswa Int
noTelpSiswa String
alamatSiswa String
studentSched StudentSched[]
......@@ -60,8 +60,8 @@ model Schedule {
idJadwal Int @id @default(autoincrement())
hari String
sesi Int
jamMulai DateTime @db.Timestamp()
jamSelesai DateTime @db.Timestamp()
jamMulai DateTime @db.Time()
jamSelesai DateTime @db.Time()
instructorSched InstructorSched[]
studentSched StudentSched[]
vehicleSched VehicleSched[]
......
import express, { Express } from "express"
import { PrismaClient } from '@prisma/client'
const route = express.Router();
const prisma = new PrismaClient()
route.get('/', async (req,res)=>{
const schedules = await prisma.schedule.findMany()
res.json(schedules)
})
route.get('/:id', async (req,res)=>{
const id = Number(req.params.id)
try{
const schedule = await prisma.schedule.findFirstOrThrow(
{
where: { idJadwal: id}
}
)
res.json(schedule)
}catch(error){
res.json("Jadwal tidak ditemukan!")
}
})
route.post('/', async (req, res)=>{
const { hari,sesi,jamMulai,jamSelesai } = req.body
try {
const CreateSchedule = await prisma.schedule.create({
data : {
hari,
sesi,
jamMulai,
jamSelesai
}
})
res.json(CreateSchedule)
} catch (error){
res.json("Gagal Membuat Schedule")
}
})
route.put('/:id', async (req, res)=>{
const id = Number(req.params.id)
const { hari,sesi,jamMulai,jamSelesai } = req.body
try {
const updateSchedule = await prisma.schedule.update({
where: {
idJadwal: id
},
data : {
hari,
sesi,
jamMulai,
jamSelesai
}
})
res.json(updateSchedule)
} catch {
res.json("Gagal Update Schedule")
}
})
route.delete('/:id', async (req, res)=>{
const id = Number(req.params.id)
try {
const deleteSchedule = await prisma.schedule.delete({
where : {
idJadwal : id
}
})
res.json(deleteSchedule)
} catch (error){
res.json("Gagal Hapus Schedule")
}
})
export default route;
\ No newline at end of file
......@@ -23,13 +23,13 @@ route.get('/:id', async (req,res)=>{
})
route.post('/', async (req, res)=>{
const { namaSiswa,kelasSiswa,umurSiswaa,noTelpSiswa,alamatSiswa } = req.body
const { namaSiswa,kelasSiswa,umurSiswa,noTelpSiswa,alamatSiswa } = req.body
try {
const CreateStudent = await prisma.student.create({
data : {
namaSiswa,
kelasSiswa,
umurSiswaa,
umurSiswa,
noTelpSiswa,
alamatSiswa
}
......@@ -42,7 +42,7 @@ route.post('/', async (req, res)=>{
route.put('/:id', async (req, res)=>{
const id = Number(req.params.id)
const { namaSiswa,kelasSiswa,umurSiswaa,noTelpSiswa,alamatSiswa } = req.body
const { namaSiswa,kelasSiswa,umurSiswa,noTelpSiswa,alamatSiswa } = req.body
try {
const updateStudent = await prisma.student.update({
where: {
......@@ -51,7 +51,7 @@ route.put('/:id', async (req, res)=>{
data : {
namaSiswa,
kelasSiswa,
umurSiswaa,
umurSiswa,
noTelpSiswa,
alamatSiswa
}
......
import express, { Express } from "express"
import { PrismaClient } from '@prisma/client'
const route = express.Router();
const prisma = new PrismaClient()
route.get('/', async (req,res)=>{
const studschedules = await prisma.studentSched.findMany()
res.json(studschedules)
})
route.get('/:id', async (req,res)=>{
const id = Number(req.params.id)
try{
const studschedule = await prisma.studentSched.findFirstOrThrow(
{
where: { idStudent: id}
}
)
res.json(studschedule)
}catch(error){
res.json("Jadwal siswa tidak ditemukan!")
}
})
route.post('/', async (req, res)=>{
const { idStudent,idJadwal } = req.body
try {
const CreateStudSchedule = await prisma.studentSched.create({
data : {
idStudent,
idJadwal
}
})
res.json(CreateStudSchedule)
} catch (error){
res.json("Gagal Membuat Jadwal Siswa")
}
})
route.put('/:idStud/:idJad', async (req, res) => {
const idStud = Number(req.params.idStud)
const idJad = Number(req.params.idJad)
const { idStudent,idJadwal } = req.body;
try {
const updateStudSchedule = await prisma.studentSched.update({
where: {
idStudent_idJadwal: {
idStudent: idStud,
idJadwal: idJad
},
},
data: {
idStudent,
idJadwal
},
});
res.json(updateStudSchedule);
} catch (error) {
res.json('Gagal Update Jadwal Siswa');
}
});
route.delete('/:idStud/:idJad', async (req, res)=>{
const idStud = Number(req.params.idStud)
const idJad = Number(req.params.idJad)
try {
const deleteStudSchedule = await prisma.studentSched.delete({
where: {
idStudent_idJadwal: {
idStudent: idStud,
idJadwal: idJad
},
},
})
res.json(deleteStudSchedule)
} catch (error){
res.json("Gagal Hapus Jadwal Siswa")
}
})
export default route;
\ No newline at end of file
......@@ -4,6 +4,8 @@ const port = process.env.PORT || 5000;
import userRoutes from './controllers/userController';
import studentRoutes from './controllers/studController';
import instructorRoutes from './controllers/insController';
import scheduleRoutes from './controllers/schedController';
import studscheduleRoutes from './controllers/studschedController';
app.listen(port, () =>{
console.log(`Server is running on port : ${port}`)
......@@ -12,4 +14,6 @@ app.listen(port, () =>{
app.use(express.json())
app.use('/user', userRoutes)
app.use('/student', studentRoutes)
app.use('/instructor', instructorRoutes)
\ No newline at end of file
app.use('/instructor', instructorRoutes)
app.use('/schedule', scheduleRoutes)
app.use('/studschedule', studscheduleRoutes)
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment