chore: add new forniture page

This commit is contained in:
Rodolfo Ruiz
2025-09-01 13:45:22 -06:00
parent b79d976c3e
commit e55d9a8cf4
5 changed files with 494 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
export default class FurnitureVariantApi {
constructor(token) {
this.baseUrl = 'https://inventory-bff.dream-views.com/api/v1/FurnitureVariant';
this.token = token;
}
headers(json = true) {
return {
accept: 'application/json',
...(json ? { 'Content-Type': 'application/json' } : {}),
...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
};
}
async getAllVariants() {
const res = await fetch(`${this.baseUrl}/GetAll`, {
method: 'GET',
headers: this.headers(false),
});
if (!res.ok) throw new Error(`GetAll error ${res.status}: ${await res.text()}`);
return res.json();
}
// Assuming similar endpoints; adjust names if backend differs.
async createVariant(payload) {
const res = await fetch(`${this.baseUrl}/Create`, {
method: 'POST',
headers: this.headers(),
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error(`Create error ${res.status}: ${await res.text()}`);
return res.json();
}
async updateVariant(payload) {
const res = await fetch(`${this.baseUrl}/Update`, {
method: 'PUT',
headers: this.headers(),
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error(`Update error ${res.status}: ${await res.text()}`);
return res.json();
}
async deleteVariant(payload) {
// If your API is soft-delete via Update status, reuse updateVariant.
const res = await fetch(`${this.baseUrl}/Delete`, {
method: 'DELETE',
headers: this.headers(),
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error(`Delete error ${res.status}: ${await res.text()}`);
return res.json();
}
}