Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ CRM_ORIGIN=http://localhost:3001
PGHOST=localhost
PGPORT=5432
PGUSER=postgres
PGPASSWORD=
PGDATABASE=database
PGPASSWORD=root
PGDATABASE=postgres
PGAPP=api
PGDEBUG=false

Expand Down
17 changes: 17 additions & 0 deletions api/migrations/201902131436_add-columns-properties-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports.up = async db => {
await db.schema.alterTable('properties', table => {
table.float('land_surface');
table.float('number_of_rooms');
table.integer('number_of_parkings');
});
};

module.exports.down = async db => {
await db.schema.alterTable('properties', table => {
table.dropColumn('land_surface');
table.dropColumn('number_of_rooms');
table.dropColumn('number_of_parkings');
});
};

module.exports.config = { transaction: true };
6 changes: 6 additions & 0 deletions api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type Property implements Node {
# The ID of an object
id: ID!
livingSurface: Float
landSurface: Float
numberOfRooms: Float
numberOfParkings: Int
createdAt: DateTime
updatedAt: DateTime
}
Expand Down Expand Up @@ -75,6 +78,9 @@ input PropertyFilters {
input PropertyInput {
id: ID
livingSurface: Float
landSurface: Float
numberOfRooms: Float
numberOfParkings: Int
}

type Query {
Expand Down
28 changes: 14 additions & 14 deletions api/src/Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class Validator {
constructor(ctx: Context, input: any, onError: () => void) {
this.user = ctx.user;
this.t = ctx.t;

this.input = input;
this.onError = onError;
}
Expand Down Expand Up @@ -173,20 +174,19 @@ export default class Validator {
is(check, message) {
this.state.promise = (
this.state.promise || Promise.resolve(this.state)
).then(
state =>
isEmpty(state.value)
? state
: Promise.resolve()
.then(() => check(state.value, message))
.then(isValid => {
if (!isValid) state.addError(message);
return state;
})
.catch(err => {
state.addError(err.message);
return Promise.resolve(state);
}),
).then(state =>
isEmpty(state.value)
? state
: Promise.resolve()
.then(() => check(state.value, message))
.then(isValid => {
if (!isValid) state.addError(message);
return state;
})
.catch(err => {
state.addError(err.message);
return Promise.resolve(state);
}),
);
return this;
}
Expand Down
10 changes: 9 additions & 1 deletion api/src/schema/PropertyInputType.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { GraphQLID, GraphQLInputObjectType, GraphQLFloat } from 'graphql';
import {
GraphQLID,
GraphQLInputObjectType,
GraphQLFloat,
GraphQLInt,
} from 'graphql';

export const fields = {
id: { type: GraphQLID },
livingSurface: { type: GraphQLFloat },
landSurface: { type: GraphQLFloat },
numberOfRooms: { type: GraphQLFloat },
numberOfParkings: { type: GraphQLInt },
};

export const PropertyInputType = new GraphQLInputObjectType({
Expand Down
17 changes: 16 additions & 1 deletion api/src/schema/PropertyType.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { GraphQLObjectType, GraphQLFloat } from 'graphql';
import { GraphQLObjectType, GraphQLFloat, GraphQLInt } from 'graphql';
import { GraphQLDateTime } from 'graphql-iso-date';

import { globalIdField } from 'graphql-relay';
Expand All @@ -17,6 +17,21 @@ export const PropertyType = new GraphQLObjectType({
resolve: parent => parent.living_surface,
},

landSurface: {
type: GraphQLFloat,
resolve: parent => parent.land_surface,
},

numberOfRooms: {
type: GraphQLFloat,
resolve: parent => parent.number_of_rooms,
},

numberOfParkings: {
type: GraphQLInt,
resolve: parent => parent.number_of_parkings,
},

createdAt: {
type: GraphQLDateTime,
resolve: parent => parent.created_at,
Expand Down
8 changes: 7 additions & 1 deletion api/src/schema/property/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export default async function(input: any, ctx: Context) {
.field('id')
.fromGlobalId('Property')
.field('livingSurface', { as: 'living_surface' })
.isFloat({ min: 20, max: 5000 }),
.isFloat({ min: 20, max: 5000 })
.field('landSurface', { as: 'land_surface' })
.isFloat({ min: 20, max: 5000 })
.field('numberOfRooms', { as: 'number_of_rooms' })
.isFloat({ min: 20, max: 5000 })
.field('numberOfParkings', { as: 'number_of_parkings' })
.isInt({ min: 20, max: 5000 }),
);

return data;
Expand Down
Loading