bus-days is a tool to manage holidays within diferent calendars and provide a solution for business days dates most common operations.
Developed for a GFT's Tech Talk by Caio Perroni Gnecco - COGC
Techs: Node.js (Nest Framework), GraphQL and MongoDB (mongoose).
This application requires a standalone local MongoDB server running at mongodb://localhost/.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode # requires MongoDB server configuration
$ npm run start:prod
As any GraphQL application there's no Swagger or endpoints, but Resolvers.
Resolvers are Queries and Mutations that can be used trough:
http://localhost:3000/graphql
This URL, when reched through a browser loads a Playground, app that allows you to test all Queries and Mutations.
This API supports 'application/graphql' requests.
-
createOrUpdateHoliday
- Input:
mutation { createOrUpdateHoliday( holiday: { date: "2019-01-01" desc: "Ano Novo" calendars: ["N"] active: true } ) { status message } }
- Sucess Output:
{ "data": { "createOrUpdateHoliday": { "status": 200, "message": "Holiday updated with sucess!" } } }
- Input:
-
createOrUpdateHolidays
- Input:
mutation { createOrUpdateHolidays( input: { holidays: [ { date: "2019-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2020-01-01", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2020-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2021-01-01", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2021-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2022-01-01", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2022-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2023-01-01", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2023-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2024-01-01", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2024-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2025-01-01", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2025-12-31", desc: "Ano Novo", calendars: ["N"], active: true } { date: "2026-01-01", desc: "Ano Novo", calendars: ["N"], active: true } ] } ) { status message } }
- Sucess Output:
{ "data": { "createOrUpdateHolidays": { "status": 200, "message": "Holidays updated with sucess!" } } }
- Input:
-
switchHoliday
- Input:
mutation { switchHoliday(date: "2019-01-01") { status message } }
- Sucess Output:
{ "data": { "switchHoliday": { "status": 200, "message": "Holiday deactivated with sucess!" || "Holiday activated with sucess!" } } }
- Input:
-
findOne
- Input:
query { findOne(date: "2019-01-01") { date desc calendars active } }
- Sucess Output:
{ "data": { "findOne": { "date": "2019-01-01T00:00:00.000Z", "desc": "Ano Novo", "calendars": [ "N" ], "active": true } } }
-
findAll
- Input:
query { findAll { date desc calendars active } }
- Sucess Output:
{ "data": { "findAll": [ { "date": "2019-01-01T00:00:00.000Z", "desc": "Ano Novo", "calendars": [ "N" ], "active": false }, { "date": "2019-12-31T00:00:00.000Z", "desc": "Ano Novo", "calendars": [ "N" ], "active": true }, { "date": "2020-01-01T00:00:00.000Z", "desc": "Ano Novo", "calendars": [ "N" ], "active": true }, { "date": "2020-12-31T00:00:00.000Z", "desc": "Ano Novo", "calendars": [ "N" ], "active": true }, ... ] } }
-
todayDiffBusinessDays
- Input:
query($ndays: Float!) { todayDiffBusinessDays(input: { nDays: $ndays }) }
- Query Variables:
{"ndays": 1}
- Sucess Output:
{ "data": { "todayDiffBusinessDays": "2019-10-11T00:00:00.000Z" } }
The "Query Variable" syntax can be used also on mutations
-
dateDiffBusinessDays
- Input:
query($ndays: Float!, $date: DateTime!) { dateDiffBusinessDays(input: { dateFrom: $date, nDays: $ndays }) }
- Query Variables:
{ "ndays": 1, "date": "2019-10-10" }
- Sucess Output:
{ "data": { "dateDiffBusinessDays": "2019-10-11T00:00:00.000Z" } }
-
businessDaysDiffToday
- Input:
query($ndays: Float!) { businessDaysDiffToday(input: { nDays: $ndays, dateTo: "2019-10-15" }) }
- Query Variables:
{ "ndays": 1 }
- Sucess Output:
{ "data": { "businessDaysDiffToday": 3 } }
-
businessDaysDiffDate
- Input:
query($dateFrom: DateTime!, $dateTo: DateTime!) { businessDaysDiffDate(input: { dateFrom: $dateFrom, dateTo: $dateTo }) }
- Query Variables:
{ "dateFrom": "2019-10-10", "dateTo": "2019-10-15" }
- Sucess Output:
{ "data": { "businessDaysDiffDate": 3 } }
You can use GraphQL with HTTP also. Read:
https://graphql.org/learn/serving-over-http/
- Author - Caio Perroni Gnecco
Nest is MIT licensed.