u
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { getStore } from './store.js';
|
||||
import { formatAttachments } from '../util/manifestAttachment.js';
|
||||
|
||||
function round2(num) {
|
||||
return Math.round((Number(num) || 0) * 100) / 100;
|
||||
@@ -47,13 +48,19 @@ export async function list(googleAuthId, opts) {
|
||||
const result = await store.quote.list(googleAuthId, opts);
|
||||
if (Array.isArray(result)) {
|
||||
const filesList = await Promise.all(
|
||||
result.map((q) => store.manifestattachment.listByManifestId(googleAuthId, q.id).catch(() => []))
|
||||
result.map(async (q) => {
|
||||
const raw = await store.manifestattachment.listByManifestId(googleAuthId, q.id).catch(() => []);
|
||||
return formatAttachments(raw);
|
||||
})
|
||||
);
|
||||
return result.map((q, i) => enrichQuote(q, filesList[i]));
|
||||
}
|
||||
if (result && Array.isArray(result.quotes)) {
|
||||
const filesList = await Promise.all(
|
||||
result.quotes.map((q) => store.manifestattachment.listByManifestId(googleAuthId, q.id).catch(() => []))
|
||||
result.quotes.map(async (q) => {
|
||||
const raw = await store.manifestattachment.listByManifestId(googleAuthId, q.id).catch(() => []);
|
||||
return formatAttachments(raw);
|
||||
})
|
||||
);
|
||||
return {
|
||||
...result,
|
||||
@@ -65,10 +72,11 @@ export async function list(googleAuthId, opts) {
|
||||
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
const [quote, files] = await Promise.all([
|
||||
const [quote, rawFiles] = await Promise.all([
|
||||
store.quote.getById(googleAuthId, id),
|
||||
store.manifestattachment.listByManifestId(googleAuthId, id).catch(() => []),
|
||||
]);
|
||||
const files = await formatAttachments(rawFiles);
|
||||
return enrichQuote(quote, files);
|
||||
}
|
||||
|
||||
@@ -80,10 +88,11 @@ export async function create(googleAuthId, data) {
|
||||
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
const [quote, files] = await Promise.all([
|
||||
const [quote, rawFiles] = await Promise.all([
|
||||
store.quote.update(googleAuthId, id, data),
|
||||
store.manifestattachment.listByManifestId(googleAuthId, id).catch(() => []),
|
||||
]);
|
||||
const files = await formatAttachments(rawFiles);
|
||||
return enrichQuote(quote, files);
|
||||
}
|
||||
|
||||
@@ -104,12 +113,14 @@ export async function getFile(googleAuthId, quoteId, fileId) {
|
||||
|
||||
export async function addAttachment(googleAuthId, quoteId, data) {
|
||||
const store = await getStore();
|
||||
return store.manifestattachment.add(googleAuthId, quoteId, data);
|
||||
const raw = await store.manifestattachment.add(googleAuthId, quoteId, data);
|
||||
return formatAttachments([raw]).then((r) => r[0]);
|
||||
}
|
||||
|
||||
export async function listAttachments(googleAuthId, quoteId) {
|
||||
const store = await getStore();
|
||||
return store.manifestattachment.listByManifestId(googleAuthId, quoteId);
|
||||
const raw = await store.manifestattachment.listByManifestId(googleAuthId, quoteId);
|
||||
return formatAttachments(raw);
|
||||
}
|
||||
|
||||
export async function removeAttachment(googleAuthId, quoteId, fileId) {
|
||||
|
||||
Reference in New Issue
Block a user