Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,39 @@
});

async function getDocuments(search: string = null) {
const documentList = {
total: 0,
documents: []
};

if (value) {
if (isRelationshipToMany(attribute)) {
documentList.documents.concat($doc[attribute.key]);
documentList.total += $doc[attribute.key].length;
} else {
documentList.documents.push($doc[attribute.key]);
documentList.total += 1;
}
}

if (search) {
const documents = await sdk.forProject.databases.listDocuments(
databaseId,
attribute.relatedCollection,
[Query.search('$id', search), Query.orderDesc('$createdAt')]
[`startsWith("$id", "${search}")`, Query.orderDesc('$createdAt')]
);
return documents;
documentList.documents.concat(documents.documents);
documentList.total += documents.total;
} else {
const documents = await sdk.forProject.databases.listDocuments(
databaseId,
attribute.relatedCollection
);
return documents;
documentList.documents.concat(documents.documents);
documentList.total += documents.total;
}

return documentList;
}

//Reactive statements
Expand Down