Skip to content

Commit

Permalink
extracted date util to util.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
alxford45 committed Nov 29, 2020
1 parent 448eef3 commit b0a0c42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
26 changes: 2 additions & 24 deletions api/src/ticket/ticket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CreateTicketDTO } from './dto/create-ticket.dto';
import { DeviceDTO } from './dto/device.dto';
import { TicketDTO, TicketType } from './dto/ticket.dto';
import { UpdateTicketDto } from './dto/update-ticket.dto';
import { createDate } from 'src/util';

@Injectable()
export class TicketService {
Expand Down Expand Up @@ -113,7 +114,7 @@ export class TicketService {
const status = 'OPEN';

/* Submission date set to current server time */
const submission_date = this.createDate();
const submission_date = createDate();

/* Insert new ticket into db */
const query: QueryConfig = {
Expand Down Expand Up @@ -190,29 +191,6 @@ export class TicketService {
}
}

/**
* Helper method for createTicket to get current date in SQL format
*
* @author KooiInc
* (https://stackoverflow.com/users/58186/kooiinc)
*
* @adapted from https://stackoverflow.com/questions/10632346/how-to-format-a-date-in-mm-dd-yyyy-hhmmss-format-in-javascript
* @returns Date (YYYY-MM-DD HH:MM:SS)
*/
private createDate() {
//@ts-ignore
Number.prototype.padLeft = function (base, chr) {
var len = String(base || 10).length - String(this).length + 1;
return len > 0 ? new Array(len).join(chr || '0') + this : this;
};
const d = new Date(Date.now());
const date =
[d.getFullYear(), d.getMonth() + 1, d.getDate()].join('-') +
' ' +
[d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
return date;
}

/* WORKING Implementation */
async create(createCombinedDTO: CreateCombinedDTO) {
/* Response Accumulator */
Expand Down
22 changes: 22 additions & 0 deletions api/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Helper method for createTicket to get current date in SQL format
*
* @author KooiInc
* (https://stackoverflow.com/users/58186/kooiinc)
*
* @adapted from https://stackoverflow.com/questions/10632346/how-to-format-a-date-in-mm-dd-yyyy-hhmmss-format-in-javascript
* @returns Date (YYYY-MM-DD HH:MM:SS)
*/
export const createDate = () => {
//@ts-ignore
Number.prototype.padLeft = function (base, chr) {
var len = String(base || 10).length - String(this).length + 1;
return len > 0 ? new Array(len).join(chr || '0') + this : this;
};
const d = new Date(Date.now());
const date =
[d.getFullYear(), d.getMonth() + 1, d.getDate()].join('-') +
' ' +
[d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
return date;
};

0 comments on commit b0a0c42

Please sign in to comment.