feat(week-from-obj): initial commit
This commit is contained in:
parent
7ffe5badc7
commit
6526b849ef
|
@ -1,7 +1,7 @@
|
|||
function getAryThisWeek(date){
|
||||
const dateToday=new Date();
|
||||
let dateIncrement=new Date(dateToday);
|
||||
aryThisWeek=[];
|
||||
const aryThisWeek=[];
|
||||
for(var i=0;i<7;i++){
|
||||
aryThisWeek[i]=new Date(dateIncrement);
|
||||
dateIncrement=new Date(dateIncrement.setDate(dateIncrement.getDate()+1));
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
.env*
|
|
@ -0,0 +1,21 @@
|
|||
## Overview
|
||||
|
||||
tbc
|
||||
|
||||
## Preparation
|
||||
Run the following command in your favorite terminal to install dependenies.
|
||||
```
|
||||
npm i
|
||||
```
|
||||
## Development setup
|
||||
Run the following command in your favorite terminal if you fancy log messages for debugging.
|
||||
```
|
||||
export DEBUG=$DEBUG,debug,ary-this-week
|
||||
```
|
||||
Run the following command in your favorite terminal to start the service in development mode.
|
||||
```
|
||||
npm run dev
|
||||
```
|
||||
## Production deployment
|
||||
|
||||
tbc
|
|
@ -0,0 +1,13 @@
|
|||
function getAryThisWeek(date){
|
||||
const dateToday=new Date();
|
||||
let dateIncrement=new Date(dateToday);
|
||||
const aryThisWeek=[];
|
||||
for(var i=0;i<7;i++){
|
||||
aryThisWeek[i]=new Date(dateIncrement);
|
||||
dateIncrement=new Date(dateIncrement.setDate(dateIncrement.getDate()+1));
|
||||
}
|
||||
return aryThisWeek;
|
||||
}
|
||||
module.exports={
|
||||
getAryThisWeek
|
||||
};
|
|
@ -0,0 +1,63 @@
|
|||
const axios=require('axios');
|
||||
const debug=require('debug')('debug');
|
||||
const aryThisWeek=require('./ary-this-week');
|
||||
const routeService=require('./service');
|
||||
|
||||
run().catch(err => {
|
||||
debug('run: error')
|
||||
console.log(err)
|
||||
});
|
||||
|
||||
async function run() {
|
||||
debug('run started...')
|
||||
const thisWeek=aryThisWeek.getAryThisWeek(new Date());
|
||||
debug('thisWeek: '+thisWeek)
|
||||
|
||||
|
||||
let url = 'http://localhost:65534/service-overview';
|
||||
debug('url: '+url);
|
||||
let res={};
|
||||
res= await axios.get(url);
|
||||
if('data' in res){
|
||||
let aryServiceOverview=Object.entries(res.data);
|
||||
for(var i=1;i<2;i++){
|
||||
debug('i: '+i);
|
||||
let agencyId = aryServiceOverview[i][0];
|
||||
debug('agencyId: '+agencyId);
|
||||
let objRoutes = aryServiceOverview[i][1];
|
||||
let count = Object.keys(objRoutes).length;
|
||||
debug('objRoutes count: ' + count);
|
||||
let aryRoutes =Object.entries(objRoutes);
|
||||
for(var j=0;j<1;j++){
|
||||
debug('j: '+j);
|
||||
let routeId=aryRoutes[i][0];
|
||||
debug('routeId: ' + routeId);
|
||||
let routeShortName=aryRoutes[i][1];
|
||||
debug('routeShortName: ' + routeShortName);
|
||||
if(routeShortName){
|
||||
routeService.getService(routeShortName);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO do run over the entire agencies
|
||||
Object.entries(res.data).map((agency, key) => {
|
||||
//debug('key: ' + key);
|
||||
let objRoutes = agency[1];
|
||||
let count = Object.keys(objRoutes).length;
|
||||
//debug('count: ' + count);
|
||||
let agencyId = agency[0];
|
||||
Object.entries(objRoutes).map((route,key)=>{
|
||||
let routeId=route[0];
|
||||
let routeShortName=route[1];
|
||||
if(routeShortName){
|
||||
debug('routeShortName: ' + routeShortName);
|
||||
routeService.getService(routeShortName);
|
||||
}
|
||||
});
|
||||
});
|
||||
*/
|
||||
}else{
|
||||
debug('no data in res');
|
||||
}
|
||||
debug('run done.')
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"private": "true",
|
||||
"name": "week-from-obj",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Stefan Begerad",
|
||||
"license": "GPL-3.0",
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
const axios=require('axios');
|
||||
const debug=require('debug')('service');
|
||||
|
||||
/* TODO do not call this function when it is required/imported as module
|
||||
getService().catch(err => {
|
||||
debug('getService: error')
|
||||
console.log(err)
|
||||
});
|
||||
*/
|
||||
|
||||
async function getService(routeShortName) {
|
||||
debug('getService started...')
|
||||
//TODO clean up static final route
|
||||
routeShortName=565;
|
||||
debug('routeShortName: ' + routeShortName);
|
||||
let url = `http://localhost:65534/servicedays?routeshortname=${routeShortName}`;
|
||||
debug('url: '+url);
|
||||
let resp={};
|
||||
resp= await axios.get(url);
|
||||
if('data' in resp){
|
||||
const objServiceDays=resp.data;
|
||||
const aryServiceDays=Object.entries(objServiceDays);
|
||||
debug('aryServiceDays len: '+aryServiceDays.length);
|
||||
for(var i=0;i<1;i++){
|
||||
debug('i: '+i);
|
||||
let serviceDay=aryServiceDays[i][0];
|
||||
debug('serviceDay: '+serviceDay);
|
||||
let dateFromDay=new Date(parseInt(serviceDay,10));
|
||||
debug('dateFromDay: '+dateFromDay);
|
||||
}
|
||||
|
||||
|
||||
/* TODO do not run over the entire service days
|
||||
aryServiceDays.map((day,key)=>{
|
||||
let dateFromDay=new Date(parseInt(day[0],10));
|
||||
debug('dateFromDay: '+dateFromDay);
|
||||
});
|
||||
*/
|
||||
}else{
|
||||
debug('no data in resp');
|
||||
}
|
||||
debug('getService done.')
|
||||
}
|
||||
|
||||
module.exports={
|
||||
getService
|
||||
};
|
Loading…
Reference in New Issue