Skip to content

Commit

Permalink
solving conflicts b4 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
raa-dev committed Sep 8, 2022
2 parents 16f1cb4 + e998101 commit f011c92
Show file tree
Hide file tree
Showing 18 changed files with 862 additions and 35 deletions.
80 changes: 80 additions & 0 deletions Db/models/briefcaseModel.js
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 };
7 changes: 7 additions & 0 deletions Db/models/index.js
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 };
55 changes: 50 additions & 5 deletions Routes/briefcaseRouter.js
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 };
2 changes: 2 additions & 0 deletions Routes/documentsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
saveDocumentInBriefcase,
saveSecrets,
} from '../Db/querys.js';
import { validatorHandler } from "../middlewares/validatorHandler.js";


const storage = multer.memoryStorage();

Expand Down
1 change: 1 addition & 0 deletions Routes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import { validatorHandler } from "../middlewares/validatorHandler.js";
import {router as briefcaseRouter } from './briefcaseRouter.js';
import {router as documentRouter } from './documentsRouter.js';
// import {router as uploadsRouter } from './upload';
Expand Down
46 changes: 46 additions & 0 deletions Schemas/briefcaseSchema.js
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
}
51 changes: 51 additions & 0 deletions Schemas/complaintSchema.js
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
};
35 changes: 35 additions & 0 deletions Schemas/documentsSchema.js
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
};
26 changes: 26 additions & 0 deletions Schemas/judgeSchema.js
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
};
26 changes: 26 additions & 0 deletions Schemas/lawyerSchema.js
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
};
6 changes: 6 additions & 0 deletions Server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express';
import cors from 'cors';
import { routerApi } from '../Routes/index.js';
import { logErrors, errorHandler, boomErrorHandler } from '../middlewares/errorHandler.js'

const app = express();
const PORT = process.env.PORT || 9000;
Expand Down Expand Up @@ -30,6 +31,11 @@ app.get('/', (req, res) => {

routerApi(app);

//middlewares
app.use(logErrors);
app.use(boomErrorHandler);
app.use(errorHandler);

app.listen(PORT, () => {
console.log(`Listening in http://localhost:${PORT}/`);
});
Loading

0 comments on commit f011c92

Please sign in to comment.