Pārlūkot izejas kodu

add the description

gdias 4 mēneši atpakaļ
vecāks
revīzija
440ba080c4
2 mainītis faili ar 47 papildinājumiem un 5 dzēšanām
  1. 46 4
      src/lib/component/Product.svelte
  2. 1 1
      src/lib/component/Report.svelte

+ 46 - 4
src/lib/component/Product.svelte

@@ -40,6 +40,7 @@
 	function resetProductForm() {
 		productFormData = {
 			name: '',
+			description: '',
 			category: categories[0]?.name ?? '',
 			price: 0,
 			sendToKitchen: false
@@ -51,7 +52,12 @@
 	function handleProductSubmit(event) {
 		event.preventDefault();
 
-		if (!productFormData.name || !productFormData.category || productFormData.price <= 0) {
+		if (
+			!productFormData.name ||
+			!productFormData.category ||
+			productFormData.price <= 0 ||
+			!productFormData.description
+		) {
 			console.error('Preencha todos os campos corretamente');
 			return;
 		}
@@ -72,7 +78,10 @@
 
 		const requestOptions = {
 			method: 'POST',
-			headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
+			headers: {
+				'Content-Type': 'application/json',
+				Authorization: `Bearer ${token}`
+			},
 			body: JSON.stringify(payload),
 			redirect: 'follow'
 		};
@@ -81,8 +90,40 @@
 			.then((response) => response.json())
 			.then((res) => {
 				if (res.status === 'ok') {
+					const productId = res.data?.product_id;
+					if (!productId) {
+						console.error('Produto criado, mas ID não retornado.');
+						return;
+					}
+
+					// Chamada para adicionar a descrição
+					const descPayload = {
+						product_id: productId,
+						company_id: company,
+						description_text: productFormData.description
+					};
+
+					fetch('https://dev2.mixtech.dev.br/description/create', {
+						method: 'POST',
+						headers: {
+							'Content-Type': 'application/json',
+							Authorization: `Bearer ${token}`
+						},
+						body: JSON.stringify(descPayload),
+						redirect: 'follow'
+					})
+						.then((descRes) => descRes.json())
+						.then((descResult) => {
+							if (descResult.status === 'ok') {
+								console.log('Descrição adicionada com sucesso!');
+							} else {
+								console.error('Erro ao adicionar descrição:', descResult.msg);
+							}
+						})
+						.catch((error) => console.error('Erro na requisição de descrição:', error));
+
 					const newProduct = {
-						id: res.data?.product_id || Date.now(),
+						id: productId,
 						...productFormData
 					};
 					products = [...products, newProduct];
@@ -431,8 +472,9 @@
 						<div>
 							<p class="mb-1 block text-sm text-gray-400">Descrição do Produto</p>
 							<input
+								bind:value={productFormData.description}
 								class="w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 focus:ring-emerald-500"
-								placeholder="Descricao"
+								placeholder="Descrição"
 							/>
 						</div>
 

+ 1 - 1
src/lib/component/Report.svelte

@@ -137,7 +137,7 @@
 	}
 </script>
 
-<div class="flex w-full flex-col">
+<div class="flex w-full flex-col rounded-md bg-stone-800 p-4">
 	<div class="flex flex-grow flex-col">
 		<!-- Cabeçalho e botões de ação -->
 		<div class="mb-6 flex flex-col justify-between md:flex-row md:items-center">