generated from WildCodeSchool/create-js-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from WildCodeSchool-2023-09/dev
Dev
- Loading branch information
Showing
30 changed files
with
2,051 additions
and
365 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
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,4 +1,140 @@ | ||
create table item ( | ||
id int unsigned primary key auto_increment not null, | ||
title varchar(255) not null | ||
drop database if exists baby_place; | ||
create database baby_place; | ||
use baby_place; | ||
drop table if exists employees_assignments; | ||
drop table if exists employees_disponibilities; | ||
drop table if exists reservation; | ||
drop table if exists documents; | ||
drop table if exists employees; | ||
drop table if exists structures; | ||
drop table if exists child; | ||
drop table if exists parents; | ||
drop table if exists users; | ||
|
||
create table users ( | ||
id int auto_increment primary key, | ||
email varchar(100) unique not null, | ||
password text not null, | ||
profile enum('Structure', 'Parent', 'Employee') not null, | ||
confirmation_inscription boolean, | ||
confirmation_date_sent datetime, | ||
created_date datetime default current_timestamp, | ||
last_connection datetime, | ||
constraint unique_email unique (email) | ||
); | ||
|
||
create table parents ( | ||
id int auto_increment primary key, | ||
user_id int unique, | ||
first_name varchar(100) not null, | ||
last_name varchar(100) not null, | ||
birth_name varchar(100), | ||
terms_accepted boolean, | ||
date_acceptance_terms datetime, | ||
marital_status enum('Single', 'Married', 'Divorced', 'Other'), | ||
address varchar(100), | ||
address_complements varchar(100), | ||
zip_code varchar(5), | ||
city varchar(100), | ||
phone_number varchar(15), | ||
email varchar(100), | ||
profession varchar(100), | ||
constraint fk_parents_users foreign key (user_id) references users(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
create table child ( | ||
id int auto_increment primary key, | ||
parents_id int, | ||
first_name varchar(100) not null, | ||
last_name varchar(100) not null, | ||
date_of_birth date not null, | ||
walker boolean, | ||
name_of_doctor varchar(100), | ||
allergies text, | ||
alimentation enum('All', 'Vegan', 'Vegetarian', 'Halal', 'Kosher'), | ||
constraint fk_child_parents foreign key (parents_id) references parents(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
create table structures ( | ||
id int auto_increment primary key, | ||
user_id int unique, | ||
name varchar(100) not null, | ||
description text, | ||
address varchar(100), | ||
address_complements varchar(100), | ||
zip_code varchar(5), | ||
city varchar(100), | ||
phone_number varchar(15), | ||
email varchar(100), | ||
activities text, | ||
welcomes text, | ||
experiences text, | ||
prices decimal(10,2), | ||
constraint fk_structures_users foreign key (user_id) references users(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
create table employees ( | ||
id int auto_increment primary key, | ||
structure_id int, | ||
first_name varchar(100) not null, | ||
last_name varchar(100) not null, | ||
qualification varchar(100), | ||
max_children_capacity int, | ||
constraint fk_employees_structures foreign key (structure_id) references structures(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); | ||
|
||
create table documents ( | ||
id int auto_increment primary key, | ||
reservation_folder_id int, | ||
document_type_id int, | ||
added boolean, | ||
upload_date datetime, | ||
file_name varchar(260), | ||
storage_path varchar(500), | ||
type enum('certificate_insurance', 'certificate_vaccination', 'certificate_birth', 'certificate_aptitude', 'authorisation_care', 'proof_income', 'declaration_income', 'num_CAF', 'num_SS', 'proof_address', 'proof_professional_status', 'RIB', 'authorization_photo', 'authorisation_exit', 'family_booklet', 'divorce_decree'), | ||
origin enum('child_folder', 'parent_folder', 'reservation_folder', 'other') | ||
); | ||
|
||
create table reservation ( | ||
id int auto_increment primary key, | ||
parent_id int, | ||
document_id int, | ||
child_id int, | ||
available_place_id int, | ||
status enum('in_progress', 'waiting', 'accepted', 'refused'), | ||
rejection_reason text, | ||
reservation_date date, | ||
start_time time, | ||
end_time time, | ||
created_date datetime default current_timestamp, | ||
constraint fk_reservation_parents foreign key (parent_id) references parents(id), | ||
constraint fk_reservation_documents foreign key (document_id) references documents(id), | ||
constraint fk_reservation_child foreign key (child_id) references child(id) | ||
); | ||
|
||
create table employees_disponibilities ( | ||
id int auto_increment primary key, | ||
employee_id int, | ||
available_date date, | ||
start_time time, | ||
end_time time, | ||
number_of_places int, | ||
constraint fk_employees_disponibilities_employees foreign key (employee_id) references employees(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); | ||
|
||
create table employees_assignments ( | ||
id int auto_increment primary key, | ||
reservation_id int, | ||
employee_id int, | ||
constraint fk_employees_assignements_employees foreign key (employee_id) references employees(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); | ||
|
||
alter table documents | ||
add constraint fk_documents_reservation foreign key (reservation_folder_id) references reservation(id) ON DELETE CASCADE | ||
ON UPDATE CASCADE; |
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 |
---|---|---|
|
@@ -3,9 +3,6 @@ | |
// Load environment variables from .env file | ||
require("dotenv").config(); | ||
|
||
// Import Faker library for generating fake data | ||
const { faker } = require("@faker-js/faker"); | ||
|
||
// Import database client | ||
const database = require("./database/client"); | ||
|
||
|
@@ -19,17 +16,32 @@ const seed = async () => { | |
|
||
// Generating Seed Data | ||
|
||
// Optional: Truncate tables (remove existing data) | ||
await database.query("truncate item"); | ||
|
||
// Insert fake data into the 'item' table | ||
for (let i = 0; i < 10; i += 1) { | ||
queries.push( | ||
database.query("insert into item(title) values (?)", [ | ||
faker.lorem.word(), | ||
]) | ||
); | ||
} | ||
// Insert initial data into the database baby_place | ||
await database.query("delete from users"); | ||
queries.push( | ||
database.query( | ||
"insert into users (email, password, profile, confirmation_inscription, confirmation_date_sent, created_date, last_connection) values ('[email protected]', 'baby', 'Structure', '1', '2024-01-01 00:00:00', '2024-01-01 00:00:00', '2024-01-01 00:00:00')" | ||
) | ||
); | ||
queries.push( | ||
database.query( | ||
"insert into users (email, password, profile, confirmation_inscription, confirmation_date_sent, created_date, last_connection) values ('[email protected]', 'papapoule', 'Parent', '1', '2024-01-01 00:00:00', '2024-01-01 00:00:00', '2024-01-01 00:00:00')" | ||
) | ||
); | ||
|
||
await database.query("delete from structures"); | ||
queries.push( | ||
database.query( | ||
"insert into structures (user_id, name, description, address, address_complements, zip_code, city, phone_number, email, activities, welcomes, experiences, prices) values ('1','BabyWilder', 'lorem ipsum', '33 Wild Code Place', '', '33000', 'Bordeaux', '05.56.56.56.56', '[email protected]', 'Promenade Musique Activités déveil', 'Sorties extérieures Repas maison Foyer non fumeur', 'Formation premier secours Formation nesting Pédagogie Montessori', '3.50')" | ||
) | ||
); | ||
|
||
await database.query("delete from parents"); | ||
queries.push( | ||
database.query( | ||
"insert into parents (user_id, first_name, last_name, birth_name, terms_accepted, date_acceptance_terms, marital_status, address, address_complements, zip_code, city, phone_number, email, profession) values ('2','Papa', 'Poule', 'Poule', '1', '2024-01-01 00:00:00', 'Married', '12 impasse de la rue imaginaire', '', '33000', 'Bordeaux', '06.07.08.09.10', '[email protected]', 'Papa à domicile')" | ||
) | ||
); | ||
|
||
/* ************************************************************************* */ | ||
|
||
|
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,81 @@ | ||
const tables = require("../tables"); | ||
|
||
// B | ||
|
||
const browse = async (req, res, next) => { | ||
try { | ||
const assignements = await tables.employees_assignments.readAll(); | ||
res.json(assignements); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
// R | ||
const read = async (req, res, next) => { | ||
try { | ||
const assignement = await tables.employees_assignments.read(req.params.id); | ||
if (assignement == null) { | ||
res.sendStatus(404); | ||
} else { | ||
res.json(assignement); | ||
} | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
// E | ||
const edit = async (req, res, next) => { | ||
try { | ||
const { id } = req.params; | ||
const assignement = req.body; | ||
const [result] = await tables.employees_assignments.update({ | ||
id, | ||
...assignement, | ||
}); | ||
|
||
if (result.affectedRows === 0) { | ||
res.sendStatus(404); | ||
} else { | ||
res.sendStatus(204); | ||
} | ||
} catch (err) { | ||
res.sendStatus(500); | ||
next(err); | ||
} | ||
}; | ||
|
||
// A | ||
const add = async (req, res, next) => { | ||
const assignement = req.body; | ||
try { | ||
const insertId = await tables.employees_assignments.create(assignement); | ||
res.status(201).json({ insertId }); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
// D | ||
const destroy = async (req, res, next) => { | ||
try { | ||
const [result] = await tables.employees_assignments.delete(req.params.id); | ||
if (result.affectedRows) { | ||
res.sendStatus(204); | ||
} else { | ||
res.sendStatus(404); | ||
} | ||
} catch (err) { | ||
res.status(500).json({ message: "Couldn't delete" }); | ||
next(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
browse, | ||
read, | ||
edit, | ||
add, | ||
destroy, | ||
}; |
Oops, something went wrong.