Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Fixed datetime bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
rweisse committed Mar 4, 2017
1 parent 15d3ac7 commit 2f83734
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ src/**/*.js

.DS_Store
debug.log
release.sh
20 changes: 10 additions & 10 deletions database/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ CREATE TABLE event_transfers (
);

CREATE TABLE event_types (
eventTypeId int NOT NULL AUTO_INCREMENT,
eventTypeDesc varchar(255) NOT NULL,
eventTypeIntern bool NOT NULL,
eventTypeRealEvent bool NOT NULL,
eventTypeDeleted bool NOT NULL,
eventTypeUiMode varchar(32) NOT NULL,
eventTypeIcon varchar(32) NOT NULL,
eventTypeCountAllowed bool NOT NULL,
CONSTRAINT event_types_pk PRIMARY KEY (eventTypeId)
eventTypeId int NOT NULL AUTO_INCREMENT,
eventTypeDesc varchar(255) NOT NULL,
eventTypeIntern bool NOT NULL,
eventTypeRealEvent bool NOT NULL,
eventTypeDeleted bool NOT NULL,
eventTypeUiMode varchar(32) NOT NULL,
eventTypeIcon varchar(32) NOT NULL,
eventTypeCountAllowed bool NOT NULL,
CONSTRAINT event_types_pk PRIMARY KEY (eventTypeId)
);

CREATE TABLE events (
Expand Down Expand Up @@ -169,4 +169,4 @@ ALTER TABLE transactions ADD CONSTRAINT transactions_products FOREIGN KEY transa
REFERENCES products (productId);

ALTER TABLE transactions ADD CONSTRAINT transactions_size_types FOREIGN KEY transactions_size_types (refSizeType)
REFERENCES size_types (sizeTypeId);
REFERENCES size_types (sizeTypeId);
24 changes: 12 additions & 12 deletions database/fill_tables_samples.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (4, 5);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (5, 1);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (5, 4);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (6, 5);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (7, 9);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (8, 10);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (7, 8);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (8, 7);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (9, 9);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (10, 9);
INSERT INTO `product_sizes`(`refProduct`, `refSizeType`) VALUES (11, 10);
Expand All @@ -63,8 +63,8 @@ INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCo
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (5, 1, 1.20, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (5, 4, 3.50, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (6, 5, 2.00, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (7, 9, 1.20, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (8, 10, 1.20, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (7, 8, 1.20, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (8, 7, 1.20, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (9, 9, 0.70, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (10, 9, 1.50, 0, false);
INSERT INTO `product_additions`(`refProduct`, `refSizeType`, `additionDeliveryCosts`, `additionMinimumStock`, `additionWarningSend`) VALUES (11, 10, 4.00, 0, false);
Expand All @@ -83,10 +83,10 @@ INSERT INTO `product_crates`(`refProduct`, `refCrateType`) VALUES (3, 3);
INSERT INTO `product_crates`(`refProduct`, `refCrateType`) VALUES (4, 3);
INSERT INTO `product_crates`(`refProduct`, `refCrateType`) VALUES (9, 6);

INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (5 , 'Initialisere Lagerbestand', 0, 0, 0, now(), false, false, false);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (1 , 'Afterwork mit Basti und Alex', 500, 645.00, 1.20, now(), false, false, false);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (1 , 'Afterwork mit Robi und Ferdi', 500, 865.50, 5.42, now(), true, true, true);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (6 , 'Stura Weihnachtsfeier HS C', 500, 712.50, 0.00, now(), true, false, false);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (5 , 'Initialisere Lagerbestand', 0, 0, 0, '2017-01-01 12:00:00', false, false, false);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (1 , 'Afterwork mit Basti und Alex', 500, 645.00, 1.20, '2017-02-15 19:00:00', false, false, false);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (1 , 'Afterwork mit Robi und Ferdi', 500, 865.50, 5.42, '2017-02-22 19:00:00', true, true, true);
INSERT INTO `events`(`refEventType`, `eventDesc`, `eventCashBefore`, `eventCashAfter`, `eventTip`, `eventDT`, `eventActive`, `eventCountedCounter`, `eventCountedStorage`) VALUES (6 , 'Stura Weihnachtsfeier HS C', 500, 712.50, 0.00, '2017-03-01 17:00:00', true, false, false);

INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 1, 3, 2000, 60);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 2, 3, 400, 30);
Expand All @@ -95,17 +95,17 @@ INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transaction
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 5, 1, 24, 4);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 5, 4, 6, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 6, 5, 20, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 7, 9, 30, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 8, 10, 30, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 7, 8, 30, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 8, 7, 30, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 9, 9, 20, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 10, 9, 1, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (1, 11, 10, 4, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 1, 3, -30, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 2, 3, -10, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 3, 5, -1, -1);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 4, 6, -4, 1);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 7, 9, -2, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 8, 10, -3, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 7, 8, -2, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 8, 7, -3, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 9, 9, -10, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 10, 9, -1, 0);
INSERT INTO `transactions`(`refEvent`, `refProduct`, `refSizeType`, `transactionChangeTotal`, `transactionChangeCounter`) VALUES (2, 11, 10, -4, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/controller/event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class EventController {
if (err) return next(new InternalError());
if (rows[0].count !== 0) return next(new ForbiddenError());
}
EventService.addEvent(EventFactory.toDbObject(req.body), (err, result) => {
EventService.addEvent(EventFactory.toDbObject(req.body, new Date(req.body.datetime)), (err, result) => {
if (err) return next(new BadRequestError());
if (result) {
EventService.getById(result.insertId, (err, row) => {
Expand Down Expand Up @@ -73,7 +73,7 @@ export class EventController {

updateEvent(req, res, next) {
let eventId = parseInt(req.context.eventId, 0);
let updatedEvent: any = EventFactory.toDbObject(req.body);
let updatedEvent: any = EventFactory.toDbObject(req.body, new Date(req.body.datetime));
updatedEvent.eventId = eventId;
delete updatedEvent.eventTS;
delete updatedEvent.eventActive;
Expand Down Expand Up @@ -112,7 +112,7 @@ export class EventController {
EventService.convertTransfersToTransactions(event.id, (err, transactions) => {
if (err) return next(new InternalError());
if (!transactions.length) {
let dbEvent = EventFactory.toDbObject(event);
let dbEvent = EventFactory.toDbObject(event, new Date(req.body.datetime));
dbEvent.eventId = event.id;
EventService.updateEvent(dbEvent, (err, result) => {
if (err || !result) return next(new InternalError());
Expand All @@ -136,7 +136,7 @@ export class EventController {
}

private closeEventAndDeleteTransfers(event: Event, req, res, next) {
let dbEvent = EventFactory.toDbObject(event);
let dbEvent = EventFactory.toDbObject(event, new Date(req.body.datetime));
dbEvent.eventId = event.id;
EventService.updateEvent(dbEvent, (err, result) => {
if (err || !result) return next(new InternalError());
Expand Down
4 changes: 2 additions & 2 deletions src/shared/models/event/event-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class EventFactory {
return event;
}

static toDbObject(obj: Event): any {
static toDbObject(obj: Event, datetime: Date): any {

let dbEntry: any = {};

Expand All @@ -78,7 +78,7 @@ export class EventFactory {

if (ValueChecker.validNumber(obj.tip)) dbEntry.eventTip = obj.tip;

if (obj.datetime) dbEntry.eventDT = obj.datetime;
if (obj.datetime) dbEntry.eventDT = datetime.toLocaleString();

if (obj.active) dbEntry.eventActive = obj.active;
else dbEntry.eventActive = false;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/models/sizetype/sizetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export class SizeType {
public description: string,
public deleted: boolean
) {}
}
}

0 comments on commit 2f83734

Please sign in to comment.