Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure user metadata is created before link documents are created #2323

Merged
merged 5 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/bbui/src/Form/DatePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

const dispatch = createEventDispatcher()
const onChange = e => {
value = e.detail
dispatch("change", e.detail)
const isoString = e.detail.toISOString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this the cause of the bad date sorting issue - that it was storing actual JS objects sometimes and strings other times? I know Flatpickr emits JS date objects (and I hate Flatpickr) but there could be consequences of changing this somewhere that might have been written to expect the date objects, so it just might need checked well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, there was a mismatch between the way dates are stored in the system, between handlebars representation (which is ISO) and the way flatpickr stores it, which is just new Date().toString() from the looks of it. Updating this still seems to work with flatpickr and store the right format in the DB.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, all good then.

value = isoString
dispatch("change", isoString)
}
</script>

Expand Down
19 changes: 18 additions & 1 deletion packages/server/src/db/linkedRows/LinkController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const CouchDB = require("../index")
const { IncludeDocs, getLinkDocuments } = require("./linkUtils")
const { generateLinkID } = require("../utils")
const {
generateLinkID,
InternalTables,
getUserMetadataParams,
} = require("../utils")
const Sentry = require("@sentry/node")
const { FieldTypes, RelationshipTypes } = require("../../constants")

Expand Down Expand Up @@ -208,6 +212,19 @@ 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) {
Expand Down