Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #13

Merged
merged 31 commits into from
Dec 22, 2023
Merged

Dev #13

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
996e7ee
creation schema sql and seed
Saeba33 Dec 20, 2023
643e9d2
Merge pull request #2 from WildCodeSchool-2023-09/database
Aknolagon Dec 20, 2023
4f050ad
npm sass, react router
Aknolagon Dec 20, 2023
f4da555
Merge pull request #3 from WildCodeSchool-2023-09/dependance
Paul-DELESQUES Dec 20, 2023
68ae565
add model + controller for table structures
Paul-DELESQUES Dec 20, 2023
401a138
I create the Manager and the controller for table parents, and i conf…
FredP21 Dec 20, 2023
d3cce23
Merge pull request #4 from WildCodeSchool-2023-09/back_tables_Paul
FredP21 Dec 20, 2023
8661f26
Merge branch 'dev' into CRUD_parents
Paul-DELESQUES Dec 20, 2023
8c9351e
Merge pull request #5 from WildCodeSchool-2023-09/CRUD_parents
Aknolagon Dec 20, 2023
b137539
child controller, model, router
Aknolagon Dec 20, 2023
39c21f2
update crud for child
Aknolagon Dec 20, 2023
695b610
Merge branch 'dev' into table_pras
Aknolagon Dec 20, 2023
c0710c3
Merge pull request #6 from WildCodeSchool-2023-09/table_pras
FredP21 Dec 20, 2023
a22bd80
debug eslint router and table
Paul-DELESQUES Dec 20, 2023
617d798
Merge pull request #7 from WildCodeSchool-2023-09/debug
Saeba33 Dec 20, 2023
11bc4ed
add controller + model + routes for table documents
Paul-DELESQUES Dec 20, 2023
e460d7a
add users, assignments, disponibilities - controller, manager, router
Saeba33 Dec 20, 2023
a706628
Merge branch 'dev' into charles_tables
Paul-DELESQUES Dec 20, 2023
0b68649
Update router.js
Paul-DELESQUES Dec 20, 2023
f31ab4b
update reservation
Aknolagon Dec 21, 2023
4e7f1ee
update table reservation and child
Aknolagon Dec 21, 2023
f70447b
Merge pull request #10 from WildCodeSchool-2023-09/charles_tables
Aknolagon Dec 21, 2023
53b51da
Merge branch 'dev' into back_tables_Paul
Aknolagon Dec 21, 2023
424fe18
Merge pull request #9 from WildCodeSchool-2023-09/back_tables_Paul
Aknolagon Dec 21, 2023
a67617e
Merge branch 'dev' into table_reservation
Aknolagon Dec 21, 2023
947d6d1
Merge pull request #11 from WildCodeSchool-2023-09/table_reservation
Paul-DELESQUES Dec 21, 2023
1e27b24
tableau employees done
sadjoaldi Dec 21, 2023
b8f3a42
Merge branch 'dev' into tables_Alh
Paul-DELESQUES Dec 21, 2023
fa630f5
Update router.js
Paul-DELESQUES Dec 21, 2023
838ad3e
Update tables.js
Paul-DELESQUES Dec 21, 2023
c7eefaa
Merge pull request #12 from WildCodeSchool-2023-09/tables_Alh
Aknolagon Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DB_HOST=localhost
DB_PORT=3306
DB_USER=YOUR_DATABASE_USERNAME
DB_PASSWORD=YOUR_DATABASE_PASSWORD
DB_NAME=YOUR_DATABASE_NAME
DB_NAME=baby_place

# Frontend URL (for CORS configuration)
FRONTEND_URL=http://localhost:3000
142 changes: 139 additions & 3 deletions backend/database/schema.sql
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;
40 changes: 26 additions & 14 deletions backend/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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')"
)
);

/* ************************************************************************* */

Expand Down
26 changes: 12 additions & 14 deletions backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ const app = express();
// 4. Be sure to only have URLs in the array with domains from which you want to allow requests.
// For example: ["http://mysite.com", "http://another-domain.com"]

/*
const cors = require("cors");

app.use(
cors({
origin: [
process.env.FRONTEND_URL, // keep this one, after checking the value in `backend/.env`
"http://mysite.com",
"http://another-domain.com",
]
})
);
*/
// const cors = require("cors");

// app.use(
// cors({
// origin: [
// process.env.FRONTEND_URL, // keep this one, after checking the value in `backend/.env`
// "http://mysite.com",
// "http://another-domain.com",
// ],
// })
// );

/* ************************************************************************* */

Expand All @@ -54,7 +52,7 @@ app.use(

// Uncomment one or more of these options depending on the format of the data sent by your client:

// app.use(express.json());
app.use(express.json());
// app.use(express.urlencoded());
// app.use(express.text());
// app.use(express.raw());
Expand Down
81 changes: 81 additions & 0 deletions backend/src/controllers/assignmentsControllers.js
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,
};
Loading