Commit 0a054b71 authored by Arthur.Pautrel's avatar Arthur.Pautrel
Browse files

Last commit for TP13 (I expect)

parent 5514347e
......@@ -20,8 +20,8 @@ router.put('/update', auth.ensureSignedIn, async (req, res, next) => {
res.json(result);
})
router.delete('/delete', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.body;
router.delete('/delete/:id', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.params;
const deletedCategory = await categoryService.remove(id);
res.json(deletedCategory);
})
......
......@@ -20,8 +20,8 @@ router.put('/update', auth.ensureSignedIn, async (req, res, next) => {
res.json(result);
})
router.delete('/delete', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.body;
router.delete('/delete/:id', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.params;
const deletedItem = await itemService.remove(id);
res.json(deletedItem);
})
......
......@@ -20,8 +20,8 @@ router.put('/update', auth.ensureSignedIn, async (req, res, next) => {
res.json(result);
})
router.delete('/delete', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.body;
router.delete('/delete/:id', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.params;
const deletedPrice = await priceService.remove(id);
res.json(deletedPrice);
})
......
......@@ -16,12 +16,12 @@ router.get('/all', async (req, res) => {
router.put('/update', auth.ensureSignedIn, async (req, res, next) => {
const { _id, title, item, user, imageUrl, desc } = req.body;
const result = await itemService.update(_id, title, item, user, imageUrl, desc);
const result = await productService.update(_id, title, item, user, imageUrl, desc);
res.json(result);
})
router.delete('/delete', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.body;
router.delete('/delete/:id', auth.ensureSignedIn, async (req, res, next) => {
const { id } = req.params;
const deletedProduct = await productService.remove(id);
res.json(deletedProduct);
})
......
......@@ -52,7 +52,7 @@ const create = async (title, item, user, imageUrl, desc) => {
const update = async (id, title, item, user, imageUrl, desc) => {
try {
const updateProduct = await Items.updateOne({"_id": id}, {$set: {"title": title, "item": item, "user": user, "imageUrl": imageUrl, "desc": desc}});
const updateProduct = await Products.updateOne({"_id": id}, {$set: {"title": title, "item": item, "user": user, "imageUrl": imageUrl, "desc": desc}});
if (updateProduct) {
return {success: true, data: updateProduct};
} else {
......
<script>
import Product from "./Product.vue"
export default {
data() {
return {
categories: [],
items: [],
products: [],
categoryClickedId: "",
itemClickedId: "",
};
},
methods: {
categoryClicked: function (idCategory) {
this.categoryClickedId = idCategory;
this.itemClickedId = "";
},
itemClicked: function (idItem) {
this.itemClickedId = idItem;
}
},
async created() {
try {
const resCategories = await this.$http.get(`http://localhost:3001/category/all`);
this.categories = resCategories.data.data;
}
catch (error) {
console.log(error);
}
try {
const resItems = await this.$http.get(`http://localhost:3001/item/all`);
this.items = resItems.data.data;
}
catch (error) {
console.log(error);
}
try {
const resProducts = await this.$http.get(`http://localhost:3001/product/all`);
this.products = resProducts.data.data;
}
catch (error) {
console.log(error);
}
},
components: { Product }
}
</script>
<template>
<div id="app">
<h1>MarketPlace</h1>
</div>
<!-- Categories -->
<h2>Categories</h2>
<ul id="categories" v-for="category of categories" :key="category._id">
<li v-on:click="categoryClicked(category._id)">
{{ category.name }}
</li>
</ul>
<!-- Items -->
<h2>Items</h2>
<ul id="items" v-for="item of items" :key="item._id">
<li v-if="item.category == this.categoryClickedId" v-on:click="itemClicked(item._id)">
{{ item.name }}
</li>
</ul>
<!-- Products -->
<h2>Products</h2>
<ul v-for="product of products" :key="product._id">
<li v-if="product.item == this.itemClickedId">
<Product :product="product"/>
</li>
</ul>
</template>
<style scoped>
</style>
\ No newline at end of file
<script>
export default {
data() {
return {
prices: [],
};
},
props: {
product: "",
},
async created() {
try {
const resPrices = await this.$http.get(`http://localhost:3001/price/all`);
this.prices = resPrices.data.data;
}
catch (error) {
console.log(error);
}
}
}
</script>
<template>
<div class="borderProduct">
<span class="colorIdentifierFields">Name : </span><span>{{product.title}}</span>
<p></p>
<span class="colorIdentifierFields">Description : </span><span>{{product.desc}}</span>
<p></p>
<span class="colorIdentifierFields">Url image : </span><span>{{product.imageUrl}}</span>
<ul id="prices" v-for="price of prices" :key="price._id">
<li v-if="price.product == product._id">
{{ price.price }}
</li>
</ul>
</div>
</template>
<style scoped>
.borderProduct {
border-width:1px;
border-style:solid;
border-color:black;
border-radius: 15px;
padding: 10px;
margin: 1%;
}
</style>
\ No newline at end of file
......@@ -3,6 +3,7 @@ import axios from "axios";
var price = {
async add({ product, price, source }) {
const dataPrice = JSON.stringify({ product, price, source });
console.log(dataPrice)
const result = await axios.post('http://localhost:3001/price/create', dataPrice, {withCredentials: true, headers: {"Content-type": "application/json",} });
return result;
},
......@@ -10,9 +11,9 @@ var price = {
const result = await axios.get('http://localhost:3001/price/all', {withCredentials: true, headers: {"Content-type": "application/json",} });
return result;
},
async delete({ id }) {
const dataCategory = JSON.stringify({ id });
const result = await axios.delete('http://localhost:3001/price/delete', dataCategory, {withCredentials: true, headers: {"Content-type": "application/json",} });
async delete({id}) {
const dataPrice = JSON.stringify({id});
const result = await axios.delete(`http://localhost:3001/price/delete/${id}`, {withCredentials: true, headers: {"Content-type": "application/json",} });
return result;
}
}
......
......@@ -9,6 +9,11 @@ var product = {
async all() {
const result = await axios.get('http://localhost:3001/product/all', {withCredentials: true, headers: {"Content-type": "application/json",} });
return result;
},
async update({ _id, title, item, imageUrl, desc }) {
const dataProduct = JSON.stringify({ _id, title, item, imageUrl, desc });
const result = await axios.put('http://localhost:3001/product/update', dataProduct, {withCredentials: true, headers: {"Content-type": "application/json",} });
return result;
}
}
......
import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import RegisterView from '../views/RegisterView.vue'
import MarketView from '../views/MarketView.vue'
import HomeView from '../views/HomeView.vue'
import Dashboard from '../views/Dashboard/Dashboard.vue';
import Category from '../views/Dashboard/pages/category.vue';
......@@ -27,11 +26,6 @@ const router = createRouter({
name: 'register',
component: RegisterView
},
{
path: '/market',
name: 'market',
component: MarketView
},
{
path: '/dashboard',
name: 'dashboard',
......
......@@ -3,10 +3,8 @@ import categoryApi from "@/libs/apis/category";
import itemApi from "@/libs/apis/item";
import productApi from "@/libs/apis/product";
import priceApi from "@/libs/apis/price";
//import Button from "../../../../../../../TP08/vuejs-sample/src/components/Button.vue";
export default {
// components: { Button },
data() {
return {
categories: [],
......@@ -50,6 +48,83 @@ export default {
this.priceModalShown = true;
this.selectedProduct = product;
},
async onDeletePrices(product) {
this.selectedProduct = product;
this.prices.forEach(price => {
if (price.product == product._id) {
console.log(priceApi.delete({id: price._id}));
console.log(price._id);
}
});
let resPricesDelete = await priceApi.all();
this.prices = resPricesDelete.data.data;
},
onEditProduct(product) {
this.selectedProduct = product;
let index = 0;
for(let i=0; i < document.getElementsByClassName("inputProductId").length; i++) {
if(document.getElementsByClassName("inputProductId")[i] == product._id) {
index = i;
break;
}
}
document.getElementsByClassName("spanProductTitle")[index].style.display = "none";
document.getElementsByClassName("spanProductItem")[index].style.display = "none";
document.getElementsByClassName("spanProductImageUrl")[index].style.display = "none";
document.getElementsByClassName("spanProductDesc")[index].style.display = "none";
document.getElementsByClassName("actions")[index].style.display = "none";
document.getElementsByClassName("inputProductTitle")[index].style.display = "block";
document.getElementsByClassName("inputProductItem")[index].style.display = "block";
document.getElementsByClassName("inputProductImageUrl")[index].style.display = "block";
document.getElementsByClassName("inputProductDesc")[index].style.display = "block";
document.getElementsByClassName("validateEdit")[index].style.display = "block";
document.getElementsByClassName("cancelEdit")[index].style.display = "block";
},
onCancelEdit(product) {
this.selectedProduct = product;
let index = 0;
for(let i=0; i < document.getElementsByClassName("inputProductId").length; i++) {
if(document.getElementsByClassName("inputProductId")[i] == product._id) {
index = i;
break;
}
}
document.getElementsByClassName("spanProductTitle")[index].style.display = "block";
document.getElementsByClassName("spanProductItem")[index].style.display = "block";
document.getElementsByClassName("spanProductImageUrl")[index].style.display = "block";
document.getElementsByClassName("spanProductDesc")[index].style.display = "block";
document.getElementsByClassName("actions")[index].style.display = "block";
document.getElementsByClassName("inputProductTitle")[index].style.display = "none";
document.getElementsByClassName("inputProductItem")[index].style.display = "none";
document.getElementsByClassName("inputProductImageUrl")[index].style.display = "none";
document.getElementsByClassName("inputProductDesc")[index].style.display = "none";
document.getElementsByClassName("validateEdit")[index].style.display = "none";
document.getElementsByClassName("cancelEdit")[index].style.display = "none";
},
async onSendEdit(product) {
this.selectedProduct = product;
let index = 0;
for(let i=0; i < document.getElementsByClassName("inputProductId").length; i++) {
if(document.getElementsByClassName("inputProductId")[i] == product._id) {
index = i;
break;
}
}
let _id = document.getElementsByClassName("inputProductId")[index].value;
let title = document.getElementsByClassName("inputProductTitle")[index].value;
let item = document.getElementsByClassName("inputProductItem")[index].value;
let imageUrl = document.getElementsByClassName("inputProductImageUrl")[index].value;
let desc = document.getElementsByClassName("inputProductDesc")[index].value;
if (item == "") {
item = undefined;
}
await productApi.update({_id, title, item, imageUrl, desc});
const resProducts = await productApi.all();
this.products = resProducts.data.data;
this.onCancelEdit(product);
},
async onAddPrice(e) {
e.preventDefault();
const { price, source, selectedProduct } = this;
......@@ -65,14 +140,13 @@ export default {
return;
}
const resPproducts = await productApi.all();
this.products = resPproducts.data.data;
const resProducts = await productApi.all();
this.products = resProducts.data.data;
this.price = this.source = this.selectedProduct = "";
const resPricesAdd = await priceApi.all();
this.prices = resPricesAdd.data.data;
},
},
// computed: {
// },
async mounted() {
const resCategories = await categoryApi.all();
this.categories = resCategories.data.data;
......@@ -152,7 +226,9 @@ export default {
</tr>
<tr v-for="product in products" :key="product.name">
<td>{{ product.title }}</td>
<td><span class="spanProductTitle">{{ product.title }}<br></span>
<input type="text" class="inputProductTitle" :value="product.title" />
<input type="text" class="inputProductId" :value="product._id" /></td>
<td>
<ul>
<li v-for="price in prices" :key="price._id">
......@@ -162,22 +238,41 @@ export default {
</ul>
</td>
<template v-for="item of items" :key="item._id">
<td class="box" v-if="item._id == product.item">{{ item.name }}</td>
<td class="box" v-if="item._id == product.item">
<span class="spanProductItem">{{ item.name }} </span>
<select
v-model="itemId"
class="inputProductItem"
>
<option v-for="item in items" :key="item.name" :value="item._id">
{{ item.name }}
</option>
</select></td>
</template>
<td>{{ product.imageUrl }}</td>
<td>{{ product.desc }}</td>
<td><span class="spanProductImageUrl">{{ product.imageUrl }}</span>
<input type="text" class="inputProductImageUrl" :value="product.imageUrl" /></td>
<td><span class="spanProductDesc">{{ product.desc }}</span>
<input type="text" class="inputProductDesc" :value="product.desc" /></td>
<td>
<div class="flex flex-col space-y-2">
<button class="hover:text-green-600 hover:font-bold">Edit</button>
<button class="hover:text-green-600 hover:font-bold">
Delete
</button>
<button
v-on:click="onSelectProduct(product)"
<button class="validateEdit" v-on:click="onSendEdit(product)">OK</button>
<button class="cancelEdit" v-on:click="onCancelEdit(product)">Cancel</button>
<div class="actions">
<div class="flex flex-col space-y-2">
<button
class="hover:text-green-600 hover:font-bold"
>
Add price
</button>
v-on:click="onEditProduct(product)">Edit</button>
<button
class="hover:text-green-600 hover:font-bold"
v-on:click="onDeletePrices(product)">
Delete prices
</button>
<button
v-on:click="onSelectProduct(product)"
class="hover:text-green-600 hover:font-bold"
>
Add price
</button>
</div>
</div>
</td>
</tr>
......@@ -263,6 +358,10 @@ export default {
</template>
<style>
.inputProductTitle, .inputProductId, .inputProductItem, .inputProductImageUrl, .inputProductDesc, .validateEdit, .cancelEdit {
display: none;
}
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment