From 8c6460ddb1a68f5251b0f046a65b1c7ad8b7375c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Aug 2021 13:00:15 +0100 Subject: [PATCH 1/5] ensure user metadata is created before link documents are created --- packages/server/src/db/linkedRows/LinkController.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/server/src/db/linkedRows/LinkController.js b/packages/server/src/db/linkedRows/LinkController.js index d526bf159b..27b230f30a 100644 --- a/packages/server/src/db/linkedRows/LinkController.js +++ b/packages/server/src/db/linkedRows/LinkController.js @@ -1,6 +1,6 @@ const CouchDB = require("../index") const { IncludeDocs, getLinkDocuments } = require("./linkUtils") -const { generateLinkID } = require("../utils") +const { generateLinkID, InternalTables, generateUserMetadataID, getUserMetadataParams } = require("../utils") const Sentry = require("@sentry/node") const { FieldTypes, RelationshipTypes } = require("../../constants") @@ -208,6 +208,15 @@ class LinkController { const linkedTable = await this._db.get(field.tableId) const linkedSchema = linkedTable.schema[field.fieldName] + // We need to map the global users to metadata in each app for relationships + if (field.tableId === InternalTables.USER_METADATA) { + const users = await this._db.allDocs(getUserMetadataParams(null, {})) + const metadataRequired = rowField.filter(userId => !users.rows.some(user => user.id === userId)) + + // ensure non-existing user metadata is created in the app DB + await this._db.bulkDocs(metadataRequired.map(userId => ({ _id: userId }))) + } + // iterate through the link IDs in the row field, see if any don't exist already for (let linkId of rowField) { if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) { From 7d49634c6d6124c99b516134b38f6f2663e6060e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Aug 2021 17:41:01 +0100 Subject: [PATCH 2/5] fix date sorting --- packages/bbui/src/Form/DatePicker.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/bbui/src/Form/DatePicker.svelte b/packages/bbui/src/Form/DatePicker.svelte index cc2ed50ead..14548bed67 100644 --- a/packages/bbui/src/Form/DatePicker.svelte +++ b/packages/bbui/src/Form/DatePicker.svelte @@ -14,6 +14,7 @@ const dispatch = createEventDispatcher() const onChange = e => { value = e.detail + console.log(value.toISOString()) dispatch("change", e.detail) } From 962e940aab4bb7e6dfd87bd62507c569b1b7abf0 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Aug 2021 17:41:11 +0100 Subject: [PATCH 3/5] fix date sorting --- packages/bbui/src/Form/DatePicker.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bbui/src/Form/DatePicker.svelte b/packages/bbui/src/Form/DatePicker.svelte index 14548bed67..9e0c40b11d 100644 --- a/packages/bbui/src/Form/DatePicker.svelte +++ b/packages/bbui/src/Form/DatePicker.svelte @@ -13,9 +13,9 @@ const dispatch = createEventDispatcher() const onChange = e => { - value = e.detail - console.log(value.toISOString()) - dispatch("change", e.detail) + const isoString = e.detail.toISOString() + value = isoString + dispatch("change", isoString) } From da67de5c8b01b844ee0e3822bec54425f6e23644 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Aug 2021 17:46:28 +0100 Subject: [PATCH 4/5] lint --- packages/server/src/db/linkedRows/LinkController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/db/linkedRows/LinkController.js b/packages/server/src/db/linkedRows/LinkController.js index 27b230f30a..5420c99300 100644 --- a/packages/server/src/db/linkedRows/LinkController.js +++ b/packages/server/src/db/linkedRows/LinkController.js @@ -1,6 +1,6 @@ const CouchDB = require("../index") const { IncludeDocs, getLinkDocuments } = require("./linkUtils") -const { generateLinkID, InternalTables, generateUserMetadataID, getUserMetadataParams } = require("../utils") +const { generateLinkID, InternalTables, getUserMetadataParams } = require("../utils") const Sentry = require("@sentry/node") const { FieldTypes, RelationshipTypes } = require("../../constants") From e6019bf3c7e301f15499cd947f23e0503820df2e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 11 Aug 2021 20:34:45 +0100 Subject: [PATCH 5/5] linting :sparkles: --- .../server/src/db/linkedRows/LinkController.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/server/src/db/linkedRows/LinkController.js b/packages/server/src/db/linkedRows/LinkController.js index 5420c99300..b66e2debb5 100644 --- a/packages/server/src/db/linkedRows/LinkController.js +++ b/packages/server/src/db/linkedRows/LinkController.js @@ -1,6 +1,10 @@ const CouchDB = require("../index") const { IncludeDocs, getLinkDocuments } = require("./linkUtils") -const { generateLinkID, InternalTables, getUserMetadataParams } = require("../utils") +const { + generateLinkID, + InternalTables, + getUserMetadataParams, +} = require("../utils") const Sentry = require("@sentry/node") const { FieldTypes, RelationshipTypes } = require("../../constants") @@ -211,10 +215,14 @@ class LinkController { // We need to map the global users to metadata in each app for relationships if (field.tableId === InternalTables.USER_METADATA) { const users = await this._db.allDocs(getUserMetadataParams(null, {})) - const metadataRequired = rowField.filter(userId => !users.rows.some(user => user.id === userId)) + const metadataRequired = rowField.filter( + userId => !users.rows.some(user => user.id === userId) + ) // ensure non-existing user metadata is created in the app DB - await this._db.bulkDocs(metadataRequired.map(userId => ({ _id: userId }))) + await this._db.bulkDocs( + metadataRequired.map(userId => ({ _id: userId })) + ) } // iterate through the link IDs in the row field, see if any don't exist already