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

feat(api): Return schema validator output for derivative datasets #2896

Merged
merged 1 commit into from
Sep 15, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { description } from './description.js'

export async function datasetType(dsOrSnapshot): Promise<'schema' | 'legacy'> {
const dsDescription = await description(dsOrSnapshot)
return dsDescription.DatasetType === 'derivative' ? 'schema' : 'legacy'
}
15 changes: 13 additions & 2 deletions packages/openneuro-server/src/graphql/resolvers/issues.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import Issue from '../../models/issue'
import { datasetType } from './datasetType'
import { revalidate } from './validation.js'

/**
* Issues resolver
*/
export const issues = (dataset, _, { userInfo }) => {
export const issues = async (dataset, _, { userInfo }) => {
return Issue.findOne({
id: dataset.revision,
datasetId: dataset.id,
// Match if we have no validatorMetadata or the correct 'legacy' / 'schema' value if we do
$or: [
{ 'validatorMetadata.validator': await datasetType(dataset) },
{ validatorMetadata: { $exists: false } },
],
})
.exec()
.then(data => {
Expand All @@ -26,11 +32,16 @@ export const issues = (dataset, _, { userInfo }) => {
/**
* Snapshot issues resolver
*/
export const snapshotIssues = snapshot => {
export const snapshotIssues = async snapshot => {
const datasetId = snapshot.id.split(':')[0]
return Issue.findOne({
id: snapshot.hexsha,
datasetId,
// Match if we have no validatorMetadata or the correct 'legacy' / 'schema' value if we do
$or: [
{ 'validatorMetadata.validator': await datasetType(snapshot) },
{ validatorMetadata: { $exists: false } },
],
})
.exec()
.then(data => (data ? data.issues : null))
Expand Down
12 changes: 11 additions & 1 deletion packages/openneuro-server/src/graphql/resolvers/summary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Summary, { SummaryDocument } from '../../models/summary'
import { datasetType } from './datasetType'

/**
* Summary resolver
Expand All @@ -8,6 +9,11 @@ export async function summary(dataset): Promise<Partial<SummaryDocument>> {
await Summary.findOne({
id: dataset.revision,
datasetId: dataset.id,
// Match if we have no validatorMetadata or the correct 'legacy' / 'schema' value if we do
$or: [
{ 'validatorMetadata.validator': await datasetType(dataset) },
{ validatorMetadata: { $exists: false } },
],
}).exec()
)?.toObject()
if (datasetSummary) {
Expand All @@ -27,7 +33,11 @@ export async function summary(dataset): Promise<Partial<SummaryDocument>> {
*/
export const updateSummary = (obj, args) => {
return Summary.updateOne(
{ id: args.summary.id, datasetId: args.summary.datasetId },
{
id: args.summary.id,
datasetId: args.summary.datasetId,
validatorMetadata: args.summary.validatorMetadata,
},
args.summary,
{
upsert: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { redlock } from '../../libs/redis.js'
*/
export const updateValidation = (obj, args) => {
return Issue.updateOne(
{ id: args.validation.id, datasetId: args.validation.datasetId },
{
id: args.validation.id,
datasetId: args.validation.datasetId,
validatorMetadata: args.validation.validatorMetadata,
},
args.validation,
{
upsert: true,
Expand Down