diff --git a/src/lib/services/context-schema.js b/src/lib/services/context-schema.ts similarity index 65% rename from src/lib/services/context-schema.js rename to src/lib/services/context-schema.ts index 6922709deb..d0c6126279 100644 --- a/src/lib/services/context-schema.js +++ b/src/lib/services/context-schema.ts @@ -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 }; diff --git a/src/lib/services/project-schema.js b/src/lib/services/project-schema.ts similarity index 62% rename from src/lib/services/project-schema.js rename to src/lib/services/project-schema.ts index d7acc9e610..d7e5f7faec 100644 --- a/src/lib/services/project-schema.js +++ b/src/lib/services/project-schema.ts @@ -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; diff --git a/src/lib/services/project-service.ts b/src/lib/services/project-service.ts index f920794736..7b86170da9 100644 --- a/src/lib/services/project-service.ts +++ b/src/lib/services/project-service.ts @@ -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 { - 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 { await this.store.get(updatedProject.id); - const project = await schema.validateAsync(updatedProject); + const project = await projectSchema.validateAsync(updatedProject); await this.store.update(project); diff --git a/src/lib/services/state-schema.ts b/src/lib/services/state-schema.ts index 54fd050dd8..53ace4f461 100644 --- a/src/lib/services/state-schema.ts +++ b/src/lib/services/state-schema.ts @@ -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