Skip to content

Commit

Permalink
Merge branch 'dev' into feature/57/validate-reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
hxfsa authored Oct 11, 2024
2 parents c1750c2 + 87dee62 commit 5412efd
Show file tree
Hide file tree
Showing 19 changed files with 292 additions and 280 deletions.
21 changes: 18 additions & 3 deletions backend/src/entities/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Field, ObjectType } from "type-graphql";
import { Field, ObjectType, registerEnumType } from "type-graphql";
import { Reservation } from "./reservation";

export enum Role {
User = "user",
Admin = "admin",
}

// this is used to export the type to the frontend through GraphQL
registerEnumType(Role, {
name: 'Role',
description: 'user role',
})

@ObjectType() //typeGraphQl
@Entity() //typeORM
export class User extends BaseEntity {
Expand All @@ -12,17 +23,21 @@ export class User extends BaseEntity {
@Column({ unique: true })
email: string;

@Field()
@Column()
firstname: string;

@Field()
@Column()
lastname: string;

@Field()
@Column()
hashedPassword: string;

@Column({ default: "USER" })
role: string;
@Field(() => Role)
@Column({ default: Role.User})
role: Role;

@Field(() => [Reservation],{ nullable: true })
@OneToMany(() => Reservation, (reservation) => reservation.user)
Expand Down
11 changes: 6 additions & 5 deletions backend/src/resolvers/UserResolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Mutation, Arg, Query, Ctx, ObjectType, Field } from "type-graphql";
import argon2 from "argon2";
import { User } from "../entities/user";
import { Role, User } from "../entities/user";
import jwt from "jsonwebtoken";
import { Context } from "src";

Expand All @@ -19,7 +19,7 @@ class UserInfo {
lastname: string;

@Field({ nullable: true })
role: string;
role: Role;
}

class UserResolver {
Expand Down Expand Up @@ -67,7 +67,8 @@ class UserResolver {
@Arg("email") email: string,
@Arg("firstname") firstname: string,
@Arg("lastname") lastname: string,
@Arg("password") password: string
@Arg("password") password: string,
@Ctx() context: any
) {
console.log("process", process.env);

Expand All @@ -89,7 +90,7 @@ class UserResolver {
{ id: userFromDB.id, email: userFromDB.email, role: userFromDB.role },
process.env.JWT_SECRET_KEY
);

context.res.setHeader("Set-Cookie", `token=${token}; Secure; HttpOnly`);
return token;
}

Expand All @@ -102,7 +103,7 @@ class UserResolver {
role: user.role,
firstname: user.firstname,
lastname: user.lastname,
isLoggedIn: true
isLoggedIn: true,
};
} else {
return { isLoggedIn: false };
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.build.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
timeout: 2s
retries: 100
db:
image: postgres
image: postgres:16.4
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 1s
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
timeout: 2s
retries: 100
db:
image: postgres
image: postgres:16.4
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 1s
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
timeout: 2s
retries: 100
db:
image: postgres
image: postgres:16.4
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 1s
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
timeout: 2s
retries: 100
db:
image: postgres
image: postgres:16.4
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 1s
Expand Down
26 changes: 15 additions & 11 deletions frontend/src/components/EditProduct/EditProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ function EditProductForm({ product, setIsModalOpen }: EditProductFormProps) {

return (
<Form
style={{ maxWidth: 600, padding: 50 }}
className="max-w-xl p-10"
wrapperCol={{ span: 16 }}
labelCol={{ span: 8 }}
name="interface admin"
name="editProductForm"
onFinish={onFinish}
initialValues={{
name: product.name,
Expand All @@ -58,28 +58,32 @@ function EditProductForm({ product, setIsModalOpen }: EditProductFormProps) {
{ required: true, message: "Un nom de produit est nécessaire" },
]}
>
<Input className="text-field" />
<Input className="rounded-md border-gray-300" />
</Form.Item>
<Form.Item label="imgUrl:" name="imgUrl">
<Input className="text-field" />

<Form.Item label="URL de l'image:" name="imgUrl">
<Input className="rounded-md border-gray-300" />
</Form.Item>

<Form.Item
label="price:"
label="Prix:"
name="price"
rules={[{ required: true, message: "Un prix est nécessaire" }]}
>
<Input className="number" />
<Input className="rounded-md border-gray-300" />
</Form.Item>

<Form.Item
label="description:"
label="Description:"
name="description"
rules={[{ required: true, message: "Une description est nécessaire" }]}
>
<Input className="text-field" />
<Input className="rounded-md border-gray-300" />
</Form.Item>

<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
<Button type="primary" htmlType="submit">
Submit
<Button type="primary" htmlType="submit" className="rounded-md">
Soumettre
</Button>
</Form.Item>
</Form>
Expand Down
34 changes: 21 additions & 13 deletions frontend/src/components/ListProductsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Table } from "antd";
import { Table, Typography } from "antd";
import { useGetAllProductsQuery } from "../generated/graphql-types";
import DeleteProductButton from "./DeleteProductButton";
import EditProductRow from "./EditProduct/EditProductRow";
import { ArticleProps, Product } from "../interface/types";

const { Title } = Typography;

function ListProductsTable() {
const { data: productsData } = useGetAllProductsQuery();

const columns = [
{
title: "ID",
dataIndex: "id",
key: "id",
},
{
title: "Nom",
dataIndex: "name",
Expand All @@ -22,6 +19,7 @@ function ListProductsTable() {
title: "Prix",
dataIndex: "price",
key: "price",
render: (price: number) => `${price.toFixed(2)} €`,
},
{
title: "Disponibles",
Expand All @@ -41,7 +39,7 @@ function ListProductsTable() {
title: "Stock total",
dataIndex: "articles",
key: "total",
render: (articles: string[]) => articles.length,
render: (articles: ArticleProps[]) => articles.length,
},
{
title: "Actions",
Expand All @@ -57,12 +55,22 @@ function ListProductsTable() {
];

return (
<Table
dataSource={productsData?.getAllProducts}
columns={columns}
pagination={{ pageSize: 10 }}
locale={{ emptyText: "No articles found" }}
/>
<div className="p-5">
<Title level={3} className="text-center text-blue-500">
Liste des produits
</Title>
<Table
dataSource={productsData?.getAllProducts}
columns={columns}
pagination={{ pageSize: 10 }}
locale={{ emptyText: "Aucun produit trouvé" }}
rowClassName="table-row"
bordered
className="rounded-lg"
tableLayout="fixed"
scroll={{ x: true }}
/>
</div>
);
}

Expand Down
Loading

0 comments on commit 5412efd

Please sign in to comment.