54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
function assertSchema(app) {
|
|
const required = {
|
|
stock_counts: [
|
|
"owner",
|
|
"chat",
|
|
"reference",
|
|
"scope",
|
|
"status",
|
|
"revision",
|
|
"review_revision",
|
|
"manifest",
|
|
"parts",
|
|
"pdfs",
|
|
],
|
|
stock_quantity_plans: [
|
|
"owner",
|
|
"chat",
|
|
"count",
|
|
"count_revision",
|
|
"review_revision",
|
|
"mode",
|
|
"rows",
|
|
"skipped",
|
|
"status",
|
|
"results",
|
|
],
|
|
stock_count_reads: ["owner", "count", "part", "source_refs", "readings"],
|
|
};
|
|
Object.keys(required).forEach((name) => {
|
|
let collection;
|
|
try {
|
|
collection = app.findCollectionByNameOrId(name);
|
|
} catch (_) {
|
|
throw new ApiError(
|
|
503,
|
|
"Stock counts require the PocketBase schema migration.",
|
|
);
|
|
}
|
|
required[name].forEach((field) => {
|
|
let found;
|
|
try {
|
|
found = collection.fields.getByName(field);
|
|
} catch (_) {
|
|
found = null;
|
|
}
|
|
if (!found)
|
|
throw new ApiError(
|
|
503,
|
|
"Stock counts require schema field " + name + "." + field,
|
|
);
|
|
});
|
|
});
|
|
}
|
|
module.exports = { assertSchema: assertSchema };
|