mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-15 01:16:22 +02:00
fix: convert schemas to typescript
This commit is contained in:
parent
dedec5c7d1
commit
ab4744e79b
@ -1,11 +1,9 @@
|
|||||||
'use strict';
|
import joi from 'joi';
|
||||||
|
import { nameType } from '../routes/util';
|
||||||
|
|
||||||
const joi = require('joi');
|
export const nameSchema = joi.object().keys({ name: nameType });
|
||||||
const { nameType } = require('../routes/util');
|
|
||||||
|
|
||||||
const nameSchema = joi.object().keys({ name: nameType });
|
export const contextSchema = joi
|
||||||
|
|
||||||
const contextSchema = joi
|
|
||||||
.object()
|
.object()
|
||||||
.keys({
|
.keys({
|
||||||
name: nameType,
|
name: nameType,
|
||||||
@ -19,5 +17,3 @@ const contextSchema = joi
|
|||||||
stickiness: joi.boolean().optional().default(false),
|
stickiness: joi.boolean().optional().default(false),
|
||||||
})
|
})
|
||||||
.options({ allowUnknown: false, stripUnknown: true });
|
.options({ allowUnknown: false, stripUnknown: true });
|
||||||
|
|
||||||
module.exports = { contextSchema, nameSchema };
|
|
@ -1,7 +1,7 @@
|
|||||||
const joi = require('joi');
|
import joi from 'joi';
|
||||||
const { nameType } = require('../routes/util');
|
import { nameType } from '../routes/util';
|
||||||
|
|
||||||
const projectSchema = joi
|
export const projectSchema = joi
|
||||||
.object()
|
.object()
|
||||||
.keys({
|
.keys({
|
||||||
id: nameType,
|
id: nameType,
|
||||||
@ -9,5 +9,3 @@ const projectSchema = joi
|
|||||||
description: joi.string().allow(null).allow('').optional(),
|
description: joi.string().allow(null).allow('').optional(),
|
||||||
})
|
})
|
||||||
.options({ allowUnknown: false, stripUnknown: true });
|
.options({ allowUnknown: false, stripUnknown: true });
|
||||||
|
|
||||||
module.exports = projectSchema;
|
|
@ -3,7 +3,7 @@ import { AccessService } from './access-service';
|
|||||||
import NameExistsError from '../error/name-exists-error';
|
import NameExistsError from '../error/name-exists-error';
|
||||||
import InvalidOperationError from '../error/invalid-operation-error';
|
import InvalidOperationError from '../error/invalid-operation-error';
|
||||||
import { nameType } from '../routes/util';
|
import { nameType } from '../routes/util';
|
||||||
import schema from './project-schema';
|
import { projectSchema} from './project-schema';
|
||||||
import NotFoundError from '../error/notfound-error';
|
import NotFoundError from '../error/notfound-error';
|
||||||
import {
|
import {
|
||||||
FEATURE_PROJECT_CHANGE,
|
FEATURE_PROJECT_CHANGE,
|
||||||
@ -118,7 +118,7 @@ export default class ProjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createProject(newProject: IProject, user: User): Promise<IProject> {
|
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.validateUniqueId(data.id);
|
||||||
|
|
||||||
await this.store.create(data);
|
await this.store.create(data);
|
||||||
@ -138,7 +138,7 @@ export default class ProjectService {
|
|||||||
|
|
||||||
async updateProject(updatedProject: IProject, user: User): Promise<void> {
|
async updateProject(updatedProject: IProject, user: User): Promise<void> {
|
||||||
await this.store.get(updatedProject.id);
|
await this.store.get(updatedProject.id);
|
||||||
const project = await schema.validateAsync(updatedProject);
|
const project = await projectSchema.validateAsync(updatedProject);
|
||||||
|
|
||||||
await this.store.update(project);
|
await this.store.update(project);
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { featureSchema, featureTagSchema } from '../schema/feature-schema';
|
|||||||
import strategySchema from './strategy-schema';
|
import strategySchema from './strategy-schema';
|
||||||
import { tagSchema } from './tag-schema';
|
import { tagSchema } from './tag-schema';
|
||||||
import { tagTypeSchema } from './tag-type-schema';
|
import { tagTypeSchema } from './tag-type-schema';
|
||||||
import projectSchema from './project-schema';
|
import { projectSchema } from './project-schema';
|
||||||
import { nameType } from '../routes/util';
|
import { nameType } from '../routes/util';
|
||||||
|
|
||||||
export const featureStrategySchema = joi
|
export const featureStrategySchema = joi
|
||||||
|
Loading…
Reference in New Issue
Block a user