-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
398 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** @format */ | ||
import { instanceModel } from 'api/odm'; | ||
import createMongooseSchema from 'json-schema-to-mongoose'; | ||
import mongoose from 'mongoose'; | ||
|
||
import schema from './dictionariesSchema'; | ||
import { Thesaurus } from './dictionariesType'; | ||
|
||
// const dictionarySchema = new mongoose.Schema({ | ||
// name: String, | ||
// values: [ | ||
// { | ||
// id: String, | ||
// label: { type: String }, | ||
// values: mongoose.Schema.Types.Mixed, | ||
// }, | ||
// ], | ||
// }); | ||
|
||
export interface ThesaurusDocument extends mongoose.Document, Thesaurus {} | ||
export default instanceModel<ThesaurusDocument>('dictionaries', createMongooseSchema({}, schema)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** @format */ | ||
|
||
export default { | ||
$async: true, | ||
title: 'Thesaurus', | ||
type: 'object', | ||
required: ['name'], | ||
properties: { | ||
name: { | ||
type: 'string', | ||
uniqueName: '', | ||
minLength: 1, | ||
}, | ||
values: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
required: ['label'], | ||
properties: { | ||
label: { | ||
type: 'id', | ||
minLength: 1, | ||
}, | ||
label: { | ||
type: 'string', | ||
minLength: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* tslint:disable */ | ||
/** | ||
* This file was automatically generated by json-schema-to-typescript. | ||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, | ||
* and run json-schema-to-typescript to regenerate this file. | ||
*/ | ||
|
||
export interface Thesaurus { | ||
name: string; | ||
values?: { | ||
label: string; | ||
[k: string]: any; | ||
}[]; | ||
[k: string]: any; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @format */ | ||
|
||
/* eslint-disable max-params */ | ||
|
||
import Ajv from 'ajv'; | ||
import ajvKeywords from 'ajv-keywords'; | ||
import model from './dictionariesModel'; | ||
import schema from './dictionariesSchema'; | ||
import { Thesaurus } from './dictionariesType'; | ||
|
||
const ajv = ajvKeywords(Ajv({ allErrors: true }), ['uniqueItemProperties']); | ||
|
||
ajv.addKeyword('uniqueName', { | ||
async: true, | ||
validate: async ( | ||
_config: any, | ||
_value: any, | ||
_propertySchema: any, | ||
_property: any, | ||
thesauri: Thesaurus | ||
) => { | ||
const [duplicated] = await model.get({ | ||
_id: { $ne: thesauri._id }, | ||
name: new RegExp(`^${thesauri.name}$` || '', 'i'), | ||
}); | ||
|
||
if (duplicated) { | ||
return false; | ||
} | ||
return true; | ||
}, | ||
}); | ||
|
||
export const validateThesauri = ajv.compile(schema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** @format */ | ||
|
||
/* eslint-disable import/first */ | ||
require('dotenv').config(); | ||
require('@babel/register')({ extensions: ['.js', '.jsx', '.ts', '.tsx'] }); | ||
|
||
const fs = require('fs'); | ||
const { compile } = require('json-schema-to-typescript'); | ||
|
||
const buildSchema = path => { | ||
const schema = require(`./${path}Schema`).default; | ||
|
||
compile(schema, schema.title).then(ts => { | ||
fs.writeFileSync(`./${path}Type.d.ts`, ts); | ||
}); | ||
}; | ||
|
||
buildSchema('app/api/thesauris/dictionaries'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'ajv-keywords'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.