From d20faedd646b538a178f94a289e4b59f1c80db14 Mon Sep 17 00:00:00 2001 From: Joan Date: Thu, 24 May 2018 11:21:44 +0200 Subject: [PATCH] Convert date to JSON #317. CR Juan --- client/core/src/lib/date.js | 19 +++++++++++++++++++ client/ticket/src/data/step-one/step-one.js | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 client/core/src/lib/date.js diff --git a/client/core/src/lib/date.js b/client/core/src/lib/date.js new file mode 100644 index 000000000..ad3d1d308 --- /dev/null +++ b/client/core/src/lib/date.js @@ -0,0 +1,19 @@ +/** + * Transforms a UTC date to JSON date without datetime. + * + * @param {date} date Date to format + * @return {String} Formatted date string + */ +export function toJsonDate(date) { + let day = date.getDate(); + let month = date.getMonth() + 1; + let year = date.getFullYear(); + + if (day < 10) + day = `0${day}` + + if (month < 10) + month = `0${month}` + + return `${year}-${month}-${day}`; +} \ No newline at end of file diff --git a/client/ticket/src/data/step-one/step-one.js b/client/ticket/src/data/step-one/step-one.js index fdfacaed6..56bd74db6 100644 --- a/client/ticket/src/data/step-one/step-one.js +++ b/client/ticket/src/data/step-one/step-one.js @@ -1,4 +1,5 @@ import ngModule from '../../module'; +import {toJsonDate} from 'core/src/lib/date'; class Controller { constructor($scope, $http, $translate, vnApp) { @@ -30,11 +31,11 @@ class Controller { let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`; let data = { - landed: this.ticket.landed, + landed: toJsonDate(this.ticket.landed), addressFk: this.ticket.addressFk, agencyModeFk: this.ticket.agencyModeFk }; - + return this.$http.post(query, data).then(res => { if (res.data) this.ticket.sale = res.data;