u
This commit is contained in:
@@ -26,7 +26,7 @@ function calculateTotalQuantity(lines = []) {
|
||||
return Math.round(qty * 1000) / 1000;
|
||||
}
|
||||
|
||||
function enrichQuote(quote) {
|
||||
function enrichQuote(quote, files = []) {
|
||||
if (!quote) return quote;
|
||||
const lines = Array.isArray(quote.lines) ? quote.lines : [];
|
||||
const positions = quote.positions !== undefined ? quote.positions : lines.length;
|
||||
@@ -38,6 +38,7 @@ function enrichQuote(quote) {
|
||||
positions,
|
||||
grossTotal,
|
||||
totalQuantity,
|
||||
files: Array.isArray(files) ? files : (quote.files || []),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,12 +46,12 @@ export async function list(googleAuthId, opts) {
|
||||
const store = await getStore();
|
||||
const result = await store.quote.list(googleAuthId, opts);
|
||||
if (Array.isArray(result)) {
|
||||
return result.map(enrichQuote);
|
||||
return result.map((q) => enrichQuote(q));
|
||||
}
|
||||
if (result && Array.isArray(result.quotes)) {
|
||||
return {
|
||||
...result,
|
||||
quotes: result.quotes.map(enrichQuote),
|
||||
quotes: result.quotes.map((q) => enrichQuote(q)),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
@@ -58,8 +59,11 @@ export async function list(googleAuthId, opts) {
|
||||
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
const quote = await store.quote.getById(googleAuthId, id);
|
||||
return enrichQuote(quote);
|
||||
const [quote, files] = await Promise.all([
|
||||
store.quote.getById(googleAuthId, id),
|
||||
store.manifestattachment.listByManifestId(googleAuthId, id).catch(() => []),
|
||||
]);
|
||||
return enrichQuote(quote, files);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, data) {
|
||||
@@ -83,3 +87,19 @@ export async function rebuildSummaries(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.quote.rebuildSummaries(googleAuthId);
|
||||
}
|
||||
|
||||
export async function getFile(googleAuthId, quoteId, fileId) {
|
||||
const store = await getStore();
|
||||
return store.manifestattachment.getById(googleAuthId, quoteId, fileId);
|
||||
}
|
||||
|
||||
export async function addAttachment(googleAuthId, quoteId, data) {
|
||||
const store = await getStore();
|
||||
return store.manifestattachment.add(googleAuthId, quoteId, data);
|
||||
}
|
||||
|
||||
export async function listAttachments(googleAuthId, quoteId) {
|
||||
const store = await getStore();
|
||||
return store.manifestattachment.listByManifestId(googleAuthId, quoteId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user