Skip to content

Commit

Permalink
Prevent creating more than one versioned-notulen
Browse files Browse the repository at this point in the history
  • Loading branch information
piemonkey committed Sep 20, 2024
1 parent 09ce215 commit 8632d66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 15 additions & 4 deletions models/versioned-notulen.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class VersionedNotulen {

/**
* @typedef {Object} Params
* @property {string} [notulenUri]
* @property {string} kind
* @property {Meeting} meeting
* @property {string} html
Expand All @@ -62,9 +63,15 @@ export default class VersionedNotulen {
* @param {Params} args
* @returns {Promise<VersionedNotulen>}
*/
static async create({ kind, meeting, html, publicTreatments }) {
const versionedNotulenUuid = uuid();
const versionedNotulenUri = `http://data.lblod.info/versioned-notulen/${versionedNotulenUuid}`;
static async create({ notulenUri, kind, meeting, html, publicTreatments }) {
let versionedNotulenUuid;
let versionedNotulenUri;
if (!notulenUri) {
versionedNotulenUuid = uuid();
versionedNotulenUri = `http://data.lblod.info/versioned-notulen/${versionedNotulenUuid}`;
} else {
versionedNotulenUri = notulenUri;
}
const fileInfo = await persistContentToFile(html);
const logicalFileUri = await writeFileMetadataToDb(fileInfo);
await update(`
Expand All @@ -78,7 +85,11 @@ export default class VersionedNotulen {
a ext:VersionedNotulen;
prov:generated ${sparqlEscapeUri(logicalFileUri)};
ext:notulenKind ${sparqlEscapeString(kind)};
mu:uuid ${sparqlEscapeString(versionedNotulenUuid)};
${
versionedNotulenUuid
? `mu:uuid ${sparqlEscapeString(versionedNotulenUuid)};`
: ''
}
ext:deleted "false"^^<http://mu.semte.ch/vocabularies/typed-literals/boolean>.
${publicTreatments
.map(
Expand Down
3 changes: 3 additions & 0 deletions support/notulen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ export async function ensureVersionedNotulen(
publicTreatments = []
) {
let versionedNotulen = await VersionedNotulen.query({ meeting, kind });
let notulenUri;
if (versionedNotulen) {
console.log(
`Reusing versioned notulen ${versionedNotulen.uri} of kind ${kind}`
);
notulenUri = versionedNotulen.uri;
if (versionedNotulen.html) {
return versionedNotulen.uri;
} else {
Expand Down Expand Up @@ -147,6 +149,7 @@ export async function ensureVersionedNotulen(
html = constructHtmlForMeetingNotesFromData(data);
}
versionedNotulen = await VersionedNotulen.create({
notulenUri,
meeting,
html,
kind,
Expand Down

0 comments on commit 8632d66

Please sign in to comment.