Skip to content

Commit

Permalink
feat(*): add parameters to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Feb 24, 2017
1 parent c110e81 commit 989d033
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 51 deletions.
12 changes: 7 additions & 5 deletions src/contexts/context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Map {
};

export interface IContext {
alias: string;
name: string;
scope: Scope;
title: string;
icon: string;
Expand All @@ -26,7 +26,7 @@ export interface ContextInstance extends Sequelize.Instance<IContext> {
createdAt: Date;
updatedAt: Date;

alias: string;
name: string;
scope: Scope;
title: string;
icon: string;
Expand All @@ -44,11 +44,13 @@ export default function define(sequelize: Sequelize.Sequelize, DataTypes) {
'primaryKey': true,
'autoIncrement': true
},
'alias': {
'type': DataTypes.STRING(64)
'name': {
'type': DataTypes.STRING(64),
'allowNull': false
},
'title': {
'type': DataTypes.STRING(128)
'type': DataTypes.STRING(128),
'allowNull': false
},
'icon': {
'type': DataTypes.STRING(128)
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Server.init(serverConfigs).then((server) => {
method: 'POST',
url: '/contexts',
payload: {
alias: 'dummy',
name: 'dummy',
title: 'dummy',
scope: 'private',
map: {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/contexts/context.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as Joi from 'joi';

export const createContextModel = Joi.object().keys({
scope: Joi.string().required().valid('public', 'protected', 'private'),
alias: Joi.string(),
title: Joi.string(),
name: Joi.string().required(),
title: Joi.string().required(),
icon: Joi.string(),
map: Joi.object().required().keys({
view: Joi.object().keys({
Expand All @@ -15,7 +15,7 @@ export const createContextModel = Joi.object().keys({

export const updateContextModel = Joi.object().keys({
scope: Joi.string().valid('public', 'protected', 'private'),
alias: Joi.string(),
name: Joi.string(),
title: Joi.string(),
icon: Joi.string(),
map: Joi.object().keys({
Expand Down
42 changes: 32 additions & 10 deletions src/layers/layer.model.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import * as Sequelize from 'sequelize';

interface PropertiesLayer {
interface ViewLayer {
attribution: string;
minZoom: number;
maxZoom: number;
};

interface SourceLayer {
url: string;
};

export interface ILayer {
name: string;
title: string;
type: string;
url: string;
protected: boolean;
properties: PropertiesLayer;
view: ViewLayer;
source: SourceLayer;
};

export interface LayerInstance extends Sequelize.Instance<ILayer> {
id: string;
createdAt: Date;
updatedAt: Date;

name: string;
title: string;
type: string;
url: string;
protected: boolean;
properties: PropertiesLayer;
view: ViewLayer;
source: SourceLayer;
}

export interface LayerModel
Expand All @@ -36,8 +44,13 @@ export default function define(sequelize: Sequelize.Sequelize, DataTypes) {
'primaryKey': true,
'autoIncrement': true
},
'name': {
'type': DataTypes.STRING(64)
'title': {
'type': DataTypes.STRING(64),
'allowNull': false
},
'type': {
'type': DataTypes.STRING(32),
'allowNull': false
},
'url': {
'type': DataTypes.STRING(255),
Expand All @@ -48,13 +61,22 @@ export default function define(sequelize: Sequelize.Sequelize, DataTypes) {
'protected': {
'type': DataTypes.BOOLEAN
},
'properties': {
'view': {
'type': DataTypes.TEXT,
'get': function() {
return JSON.parse(this.getDataValue('view'));
},
'set': function(val) {
this.setDataValue('view', JSON.stringify({}));
}
},
'source': {
'type': DataTypes.TEXT,
'get': function() {
return JSON.parse(this.getDataValue('properties'));
return JSON.parse(this.getDataValue('source'));
},
'set': function(val) {
this.setDataValue('properties', JSON.stringify({}));
this.setDataValue('source', JSON.stringify({}));
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/layers/layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ Server.init(serverConfigs).then((server) => {
method: 'POST',
url: '/layers',
payload: {
name: 'dummy',
title: 'dummy',
type: 'osm',
protected: false,
properties: {}
view: {},
source: {}
}
};
server.inject(options, function(response) {
Expand Down
16 changes: 12 additions & 4 deletions src/layers/layer.validator.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import * as Joi from 'joi';

export const createLayerModel = Joi.object().keys({
name: Joi.string().max(64),
title: Joi.string().required().max(64),
type: Joi.string().required().max(32),
url: Joi.string(),
protected: Joi.boolean(),
properties: Joi.object().required().keys({
view: Joi.object().required().keys({
attribution: Joi.string(),
minZoom: Joi.number(),
maxZoom: Joi.number()
}),
source: Joi.object().required().keys({
url: Joi.string()
})
});

export const updateLayerModel = Joi.object().keys({
name: Joi.string().max(64),
title: Joi.string().max(64),
type: Joi.string().max(32),
url: Joi.string(),
protected: Joi.boolean(),
properties: Joi.object().required().keys({
view: Joi.object().required().keys({
attribution: Joi.string(),
minZoom: Joi.number(),
maxZoom: Joi.number()
}),
source: Joi.object().required().keys({
url: Joi.string()
})
});
34 changes: 20 additions & 14 deletions src/tools/tool.model.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import * as Sequelize from 'sequelize';

interface PropertiesTool {
attribution: string;
minZoom: number;
maxZoom: number;
};

export interface ITool {
name: string;
url: string;
title: string;
icon?: string;
url?: string;
protected: boolean;
properties: PropertiesTool;
options?: {[key: string]: any};
};

export interface ToolInstance extends Sequelize.Instance<ITool> {
Expand All @@ -19,9 +15,11 @@ export interface ToolInstance extends Sequelize.Instance<ITool> {
updatedAt: Date;

name: string;
url: string;
title: string;
icon?: string;
url?: string;
protected: boolean;
properties: PropertiesTool;
options?: {[key: string]: any};
}

export interface ToolModel
Expand All @@ -37,7 +35,15 @@ export default function define(sequelize: Sequelize.Sequelize, DataTypes) {
'autoIncrement': true
},
'name': {
'type': DataTypes.STRING(64)
'type': DataTypes.STRING(64),
'allowNull': false
},
'title': {
'type': DataTypes.STRING(64),
'allowNull': false
},
'icon': {
'type': DataTypes.STRING(128)
},
'url': {
'type': DataTypes.STRING(255),
Expand All @@ -48,13 +54,13 @@ export default function define(sequelize: Sequelize.Sequelize, DataTypes) {
'protected': {
'type': DataTypes.BOOLEAN
},
'properties': {
'options': {
'type': DataTypes.TEXT,
'get': function() {
return JSON.parse(this.getDataValue('properties'));
return JSON.parse(this.getDataValue('options'));
},
'set': function(val) {
this.setDataValue('properties', JSON.stringify({}));
this.setDataValue('options', JSON.stringify({}));
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/tools/tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Server.init(serverConfigs).then((server) => {
url: '/tools',
payload: {
name: 'dummy',
title: 'dummy',
protected: false,
properties: {}
options: {}
}
};
server.inject(options, function(response) {
Expand Down
18 changes: 7 additions & 11 deletions src/tools/tool.validator.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import * as Joi from 'joi';

export const createToolModel = Joi.object().keys({
name: Joi.string().max(64),
name: Joi.string().required().max(64),
title: Joi.string().required().max(64),
icon: Joi.string().max(128),
url: Joi.string(),
protected: Joi.boolean(),
properties: Joi.object().required().keys({
attribution: Joi.string(),
minZoom: Joi.number(),
maxZoom: Joi.number()
})
options: Joi.object().required()
});

export const updateToolModel = Joi.object().keys({
name: Joi.string().max(64),
title: Joi.string().max(64),
icon: Joi.string().max(128),
url: Joi.string(),
protected: Joi.boolean(),
properties: Joi.object().required().keys({
attribution: Joi.string(),
minZoom: Joi.number(),
maxZoom: Joi.number()
})
options: Joi.object().required()
});

0 comments on commit 989d033

Please sign in to comment.