-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
862 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Model, DataTypes } from 'sequelize'; | ||
|
||
const BRIEFCASE_TABLE = 'briefcase'; | ||
|
||
const briefcaseSchema = { | ||
case_id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
token_id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
type_of_demand: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
unique: true, | ||
}, | ||
place_of_case: { | ||
allowNull: false, | ||
type: DataTypes.STRING | ||
}, | ||
crime: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
crime_data: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
place_of_crime: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
name_of_plaintiff: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
name_of_defendant: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
defendants_attorney: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
plaintiffs_attorney: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
documents: { | ||
allowNull: true, | ||
type: DataTypes.BLOB | ||
}, | ||
users: { | ||
allowNull: true, | ||
type: DataTypes.STRING | ||
} | ||
} | ||
|
||
class Briefcase extends Model { | ||
static associate() { | ||
// associate | ||
} | ||
|
||
static config(sequelize) { | ||
return { | ||
sequelize, | ||
tableName: BRIEFCASE_TABLE, | ||
modelName: 'Briefcase', | ||
timestamps: false | ||
} | ||
} | ||
} | ||
|
||
|
||
export { BRIEFCASE_TABLE, briefcaseSchema, Briefcase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Briefcase, briefcaseSchema } from './briefcaseModel.js'; | ||
|
||
function setupModels(sequelize) { | ||
Briefcase.init(briefcaseSchema, Briefcase.config(sequelize)); | ||
} | ||
|
||
export { setupModels }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,63 @@ | ||
import express from "express"; | ||
import { validatorHandler } from "../middlewares/validatorHandler.js"; | ||
import { | ||
createBriefcaseSchema, | ||
updateBriefcaseSchema, | ||
getBriefcaseSchema | ||
} from "../Schemas/briefcaseSchema.js"; | ||
import { BriefcaseService } from "../Services/briefcaseServices.js"; | ||
|
||
const router = express.Router(); | ||
const service = new BriefcaseService(); | ||
//GET | ||
router.get('/', async (req, res) => { | ||
try { | ||
const briefcases = await service.find(); | ||
res.json(briefcases); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}) | ||
|
||
router.get('/', (req, res) => { | ||
router.get('/:id', async (req, res) => { | ||
try { | ||
res.json({ | ||
name: 'briefcase-example', | ||
lawyer: 'lawyer-example' | ||
}); | ||
const { id } = req.params; | ||
const briefcases = await service.findOne(id); | ||
res.json(briefcases); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}) | ||
|
||
//POST | ||
router.post('/', | ||
// validatorHandler(createBriefcaseSchema, 'body'), | ||
async (req, res) => { | ||
try { | ||
const body = req.body; | ||
const newBriefcase = await service.create(body); | ||
console.log(newBriefcase); | ||
res.status(201).json(newBriefcase); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
) | ||
|
||
//PATCH | ||
router.patch('/:id', | ||
validatorHandler(getBriefcaseSchema, 'params'), | ||
validatorHandler(updateBriefcaseSchema, 'body'), | ||
async (req, res, next) => { | ||
try { | ||
const { id } = req.params; | ||
const body = req.body; | ||
const briefcase = await service.update(id, body); | ||
res.json(briefcase); | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
); | ||
|
||
export { router }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import joi from 'joi'; | ||
|
||
const case_id = joi.string(); | ||
const type_of_demand = joi.string(); | ||
const crime = joi.string(); | ||
const crime_data = joi.string(); | ||
const name_of_plantiff = joi.string(); | ||
const plantiffs_attorney = joi.string(); | ||
const name_of_defendand = joi.string(); | ||
const defendands_attorney = joi.string(); | ||
const place_of_case = joi.string(); | ||
const place_of_crime = joi.string(); | ||
|
||
const createBriefcaseSchema = joi.object({ | ||
type_of_demand: type_of_demand.required(), | ||
crime: crime.required(), | ||
crime_data: crime_data.required(), | ||
name_of_plantiff: name_of_plantiff.required(), | ||
plantiffs_attorney: plantiffs_attorney.required(), | ||
name_of_defendand: name_of_defendand.required(), | ||
defendands_attorney: defendands_attorney.required(), | ||
place_of_case: place_of_case.required(), | ||
place_of_crime: place_of_crime.required() | ||
}); | ||
|
||
const updateBriefcaseSchema = joi.object({ | ||
type_of_demand, | ||
crime, | ||
crime_data, | ||
name_of_plantiff, | ||
plantiffs_attorney, | ||
name_of_defendand, | ||
defendands_attorney, | ||
place_of_case, | ||
place_of_crime, | ||
}); | ||
|
||
const getBriefcaseSchema = joi.object({ | ||
case_id: case_id.required() | ||
}); | ||
|
||
export { | ||
createBriefcaseSchema, | ||
updateBriefcaseSchema, | ||
getBriefcaseSchema | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import joi from 'joi'; | ||
|
||
const id = joi.number().uuid(); | ||
const type = joi.string(); | ||
const place = joi.string(); | ||
const crime = joi.string(); | ||
const crimeDate = joi.string(); | ||
const crimePlace = joi.string(); | ||
const complainantName = joi.string(); | ||
const defendandName = joi.string(); | ||
const complainantLawyer = joi.string(); | ||
const defendandLawyer = joi.string(); | ||
|
||
|
||
|
||
|
||
|
||
const createComplaintSchema = joi.object({ | ||
id: id.required(), | ||
type: type.required(), | ||
place: place.required(), | ||
crime: crime.required(), | ||
crimeDate: crimeDate.required(), | ||
crimePlace: crimePlace.required(), | ||
complainantName: complainantName.required(), | ||
defendandName: defendandName.required(), | ||
complainantLawyer: complainantLawyer.required(), | ||
defendandLawyer: defendandLawyer.required() | ||
}); | ||
|
||
const updateComplaintSchema = joi.object({ | ||
type, | ||
place, | ||
crime, | ||
crimeDate, | ||
crimePlace, | ||
complainantName, | ||
defendandName, | ||
complainantLawyer, | ||
defendandLawyer | ||
}); | ||
|
||
const getComplaintSchema = joi.object({ | ||
id: id.required() | ||
}); | ||
|
||
export { | ||
createComplaintSchema, | ||
updateComplaintSchema, | ||
getComplaintSchema | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import joi from 'joi'; | ||
|
||
const id = joi.number().uuid(); | ||
const hash = joi.number().uuid(); | ||
const extension = joi.string().min(2).max(5); | ||
const name = joi.string().min(2).max(30); | ||
const description = joi.string(); | ||
const date = joi.string(); | ||
const type = joi.string(); | ||
|
||
const createDocumentSchema = joi.object({ | ||
id: id.required(), | ||
hash: hash.required(), | ||
extension: extension.required(), | ||
name: name.required(), | ||
description: description.required(), | ||
date: date.required(), | ||
type: type.required() | ||
}); | ||
|
||
const updateDocumentSchema = joi.object({ | ||
extension, | ||
name, | ||
description | ||
}); | ||
|
||
const getDocumentSchema = joi.object({ | ||
id: id.required() | ||
}); | ||
|
||
export { | ||
createDocumentSchema, | ||
updateDocumentSchema, | ||
getDocumentSchema | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import joi from 'joi'; | ||
|
||
const id = joi.number().uuid(); | ||
const name = joi.string().min(2).max(30); | ||
const contact = joi.string(); | ||
|
||
const createJudgeSchema = joi.object({ | ||
id: id.required(), | ||
name: name.required(), | ||
contact: contact.required() | ||
}); | ||
|
||
const updateJudgeSchema = joi.object({ | ||
name, | ||
contact | ||
}); | ||
|
||
const getJudgeSchema = joi.object({ | ||
id: id.required() | ||
}); | ||
|
||
export { | ||
createJudgeSchema, | ||
updateJudgeSchema, | ||
getJudgeSchema | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import joi from 'joi'; | ||
|
||
const id = joi.number().uuid(); | ||
const name = joi.string().min(2).max(30); | ||
const contact = joi.string(); | ||
|
||
const createLawyerSchema = joi.object({ | ||
id: id.required(), | ||
name: name.required(), | ||
contact: contact.required() | ||
}); | ||
|
||
const updateLawyerSchema = joi.object({ | ||
name, | ||
contact | ||
}); | ||
|
||
const getLawyerSchema = joi.object({ | ||
id: id.required() | ||
}); | ||
|
||
export { | ||
createLawyerSchema, | ||
updateLawyerSchema, | ||
getLawyerSchema | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.