1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: convert schemas to typescript

This commit is contained in:
Ivar Conradi Østhus 2021-09-14 20:36:40 +02:00
parent dedec5c7d1
commit ab4744e79b
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
4 changed files with 11 additions and 17 deletions

View File

@ -1,11 +1,9 @@
'use strict';
import joi from 'joi';
import { nameType } from '../routes/util';
const joi = require('joi');
const { nameType } = require('../routes/util');
export const nameSchema = joi.object().keys({ name: nameType });
const nameSchema = joi.object().keys({ name: nameType });
const contextSchema = joi
export const contextSchema = joi
.object()
.keys({
name: nameType,
@ -19,5 +17,3 @@ const contextSchema = joi
stickiness: joi.boolean().optional().default(false),
})
.options({ allowUnknown: false, stripUnknown: true });
module.exports = { contextSchema, nameSchema };

View File

@ -1,7 +1,7 @@
const joi = require('joi');
const { nameType } = require('../routes/util');
import joi from 'joi';
import { nameType } from '../routes/util';
const projectSchema = joi
export const projectSchema = joi
.object()
.keys({
id: nameType,
@ -9,5 +9,3 @@ const projectSchema = joi
description: joi.string().allow(null).allow('').optional(),
})
.options({ allowUnknown: false, stripUnknown: true });
module.exports = projectSchema;

View File

@ -3,7 +3,7 @@ import { AccessService } from './access-service';
import NameExistsError from '../error/name-exists-error';
import InvalidOperationError from '../error/invalid-operation-error';
import { nameType } from '../routes/util';
import schema from './project-schema';
import { projectSchema} from './project-schema';
import NotFoundError from '../error/notfound-error';
import {
FEATURE_PROJECT_CHANGE,
@ -118,7 +118,7 @@ export default class ProjectService {
}
async createProject(newProject: IProject, user: User): Promise<IProject> {
const data = await schema.validateAsync(newProject);
const data = await projectSchema.validateAsync(newProject);
await this.validateUniqueId(data.id);
await this.store.create(data);
@ -138,7 +138,7 @@ export default class ProjectService {
async updateProject(updatedProject: IProject, user: User): Promise<void> {
await this.store.get(updatedProject.id);
const project = await schema.validateAsync(updatedProject);
const project = await projectSchema.validateAsync(updatedProject);
await this.store.update(project);

View File

@ -3,7 +3,7 @@ import { featureSchema, featureTagSchema } from '../schema/feature-schema';
import strategySchema from './strategy-schema';
import { tagSchema } from './tag-schema';
import { tagTypeSchema } from './tag-type-schema';
import projectSchema from './project-schema';
import { projectSchema } from './project-schema';
import { nameType } from '../routes/util';
export const featureStrategySchema = joi