126 lines
3.3 KiB
JavaScript
126 lines
3.3 KiB
JavaScript
import axios from '../axios.js';
|
|
import fs from 'fs';
|
|
export const getBids = async () => {
|
|
try {
|
|
const { data } = await axios({
|
|
method: 'GET',
|
|
url: 'bids',
|
|
});
|
|
|
|
if (!data || !data?.data) {
|
|
console.log('❌ DATA IS NOT FOUND ON SERVER');
|
|
return [];
|
|
}
|
|
|
|
return data.data;
|
|
} catch (error) {
|
|
console.log('❌ ERROR IN SERVER (GET BIDS): ', error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
export const updateBid = async (id, values) => {
|
|
try {
|
|
const { data } = await axios({
|
|
method: 'PUT',
|
|
url: 'bids/' + id,
|
|
data: values,
|
|
});
|
|
|
|
if (!data || !data?.data) {
|
|
console.log('❌ UPDATE FAILURE (UPDATE BID)');
|
|
return null;
|
|
}
|
|
|
|
return data.data;
|
|
} catch (error) {
|
|
console.log('❌ ERROR IN SERVER: (UPDATE BID) ', error);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export const outBid = async (id) => {
|
|
try {
|
|
const { data } = await axios({
|
|
method: 'POST',
|
|
url: 'bids/out-bid/' + id,
|
|
});
|
|
|
|
if (!data || !data?.data) {
|
|
console.log('❌ OUT BID UPDATE FAILURE');
|
|
return false;
|
|
}
|
|
|
|
return data.data;
|
|
} catch (error) {
|
|
console.log('❌ ERROR IN SERVER (OUT BID UPDATE): ', error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
export const pushPrice = async (values) => {
|
|
try {
|
|
const { data } = await axios({
|
|
method: 'POST',
|
|
url: 'bid-histories',
|
|
data: values,
|
|
});
|
|
|
|
if (!data || !data?.data) {
|
|
console.log('❌ PUSH PRICE FAILURE');
|
|
return { status: false, data: [] };
|
|
}
|
|
|
|
return { status: true, data: data.data };
|
|
} catch (error) {
|
|
console.log('❌ ERROR IN SERVER (PUSH PRICE): ', error.response.data);
|
|
return { status: false, data: [] };
|
|
}
|
|
};
|
|
|
|
export const updateStatusByPrice = async (id, current_price) => {
|
|
try {
|
|
const { data } = await axios({
|
|
method: 'POST',
|
|
url: 'bids/update-status/' + id,
|
|
data: {
|
|
current_price: Number(current_price) | 0,
|
|
},
|
|
});
|
|
|
|
if (!data || !data?.data) {
|
|
console.log('❌ UPDATE STATUS BY PRICE FAILURE');
|
|
return { status: false, data: [] };
|
|
}
|
|
|
|
return { status: true, data: data.data };
|
|
} catch (error) {
|
|
console.log('❌ ERROR IN SERVER:(UPDATE STATUS BY PRICE) ', {
|
|
// response: error.response,
|
|
message: error.message,
|
|
});
|
|
return { status: false, data: [] };
|
|
}
|
|
};
|
|
|
|
export const updateStatusWork = async (item, filePath) => {
|
|
try {
|
|
const response = await axios({
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
url: `bids/update-status-work/${item.type}/${item.id}`,
|
|
data: {
|
|
image: fs.createReadStream(filePath),
|
|
},
|
|
});
|
|
fs.unlinkSync(filePath);
|
|
|
|
return response.data?.data;
|
|
} catch (error) {
|
|
console.error('❌ Upload failed:', error.response?.data || error.message);
|
|
return false;
|
|
}
|
|
};
|