Skip to content

Commit

Permalink
collection schema
Browse files Browse the repository at this point in the history
  • Loading branch information
theorm committed Nov 8, 2024
1 parent b723482 commit 58cb45f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
29 changes: 28 additions & 1 deletion src/models/generated/schemasPublic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,37 @@


/**
* Description of the collection object (Collection class)
* Collection details.
*/
export interface Collection {
/**
* Unique identifier of the collection.
*/
uid: string;
/**
* Title of the collection.
*/
title: string;
/**
* Description of the collection.
*/
description: string;
/**
* Access level of the collection.
*/
accessLevel: "public" | "private";
/**
* Creation date of the collection.
*/
createdAt: string;
/**
* Last update date of the collection.
*/
updatedAt: string;
/**
* Total number of items in the collection.
*/
totalItems: number;
}


Expand Down
36 changes: 31 additions & 5 deletions src/schema/schemasPublic/Collection.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Collection",
"description": "Description of the collection object (Collection class)",
"description": "Collection details.",
"type": "object",
"additionalProperties": false,
"required": ["uid"],
"properties": {
"uid": {
"type": "string",
"minLength": 2,
"maxLength": 50
"description": "Unique identifier of the collection."
},
"title": {
"type": "string",
"description": "Title of the collection."
},
"description": {
"type": "string",
"description": "Description of the collection."
},
"accessLevel": {
"type": "string",
"description": "Access level of the collection.",
"enum": ["public", "private"]
},
"createdAt": {
"type": "string",
"description": "Creation date of the collection.",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"description": "Last update date of the collection.",
"format": "date-time"
},
"totalItems": {
"type": "integer",
"description": "Total number of items in the collection."
}
}
},
"required": ["uid", "title", "description", "accessLevel", "createdAt", "updatedAt", "totalItems"]
}
12 changes: 8 additions & 4 deletions src/services/collections/collections.hooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { authenticateAround as authenticate } from '../../hooks/authenticate'
import { rateLimit } from '../../hooks/rateLimiter'
import { transformResponseDataItem, transformResponse } from '../../hooks/transformation'
import { inPublicApi } from '../../hooks/redaction'
import { transformCollection } from '../../transformers/collection'

const { queryWithCommonParams, validate, utils, REGEX_UIDS } = require('../../hooks/params')

const { STATUS_PRIVATE, STATUS_PUBLIC } = require('../../models/collections.model')
Expand Down Expand Up @@ -85,11 +89,11 @@ module.exports = {

after: {
all: [],
find: [],
get: [],
create: [],
find: [transformResponseDataItem(transformCollection, inPublicApi)],
get: [transformResponse(transformCollection, inPublicApi)],
create: [transformResponse(transformCollection, inPublicApi)],
update: [],
patch: [],
patch: [transformResponse(transformCollection, inPublicApi)],
remove: [],
},

Expand Down
23 changes: 23 additions & 0 deletions src/transformers/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Collection as CollectionInternal } from '../models/generated/schemas'
import { Collection as CollectionPublic } from '../models/generated/schemasPublic'

const toAccessLevel = (status: string): CollectionPublic['accessLevel'] => {
switch (status.toUpperCase()) {
case 'PUB':
return 'public'
default:
return 'private'
}
}

export const transformCollection = (input: CollectionInternal): CollectionPublic => {
return {
uid: input.uid,
title: input.name,
description: input.description,
createdAt: input.creationDate,
updatedAt: input.lastModifiedDate,
totalItems: Number(input.countItems),
accessLevel: toAccessLevel(input.status),
}
}

0 comments on commit 58cb45f

Please sign in to comment.