-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
136 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import moment from "moment"; | ||
import { createDbClient } from "../../gql/lib/db"; | ||
import { DAY_FORMAT } from "../../gql/constants"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
async function logEventHandler(request: NextRequest) { | ||
const { date, event } = await request.json(); | ||
const momentDate = moment(date).utc(); | ||
|
||
if (!event) { | ||
return NextResponse.json({ error: "Date is missing" }, { status: 400 }); | ||
} | ||
|
||
if (!date) { | ||
return NextResponse.json({ error: "Event is missing" }, { status: 400 }); | ||
} | ||
|
||
try { | ||
const db = await createDbClient(); | ||
const day = momentDate.format(DAY_FORMAT); | ||
|
||
await db.workTimetable.updateOne( | ||
{ day: { $eq: day } }, | ||
{ | ||
$push: { events: event }, | ||
$setOnInsert: { | ||
date: new Date(momentDate.toISOString()), | ||
day, | ||
}, | ||
}, | ||
{ upsert: true } | ||
); | ||
|
||
return NextResponse.json({}, { status: 200 }); | ||
} catch (exception) { | ||
return NextResponse.json({ error: exception }, { status: 500 }); | ||
} | ||
} | ||
|
||
export { logEventHandler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { logTime } from "../../gql/utils/log-time"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
async function logHomeArriveHandler(request: NextRequest) { | ||
const { date } = await request.json(); | ||
|
||
if (!date) { | ||
return NextResponse.json({ error: "Date is missing" }, { status: 400 }); | ||
} | ||
|
||
try { | ||
await logTime(date, "homeArriveTime"); | ||
|
||
return NextResponse.json({}, { status: 200 }); | ||
} catch (exception) { | ||
return NextResponse.json({ error: exception }, { status: 500 }); | ||
} | ||
} | ||
|
||
export { logHomeArriveHandler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { logTime } from "../../gql/utils/log-time"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
async function logHomeLeaveHandler(request: NextRequest) { | ||
const { date } = await request.json(); | ||
|
||
if (!date) { | ||
return NextResponse.json({ error: "Date is missing" }, { status: 400 }); | ||
} | ||
|
||
try { | ||
await logTime(date, "homeLeaveTime"); | ||
|
||
return NextResponse.json({}, { status: 200 }); | ||
} catch (exception) { | ||
return NextResponse.json({ error: exception }, { status: 500 }); | ||
} | ||
} | ||
|
||
export { logHomeLeaveHandler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { logTime } from "../../gql/utils/log-time"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
async function logWorkArriveHandler(request: NextRequest) { | ||
const { date } = await request.json(); | ||
|
||
if (!date) { | ||
return NextResponse.json({ error: "Date is missing" }, { status: 400 }); | ||
} | ||
|
||
try { | ||
await logTime(date, "workArriveTime"); | ||
|
||
return NextResponse.json({}, { status: 200 }); | ||
} catch (exception) { | ||
return NextResponse.json({ error: exception }, { status: 500 }); | ||
} | ||
} | ||
|
||
export { logWorkArriveHandler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { logTime } from "../../gql/utils/log-time"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
async function logWorkLeaveHandler(request: NextRequest) { | ||
const { date } = await request.json(); | ||
|
||
if (!date) { | ||
return NextResponse.json({ error: "Date is missing" }, { status: 400 }); | ||
} | ||
|
||
try { | ||
await logTime(date, "workLeaveTime"); | ||
|
||
return NextResponse.json({}, { status: 200 }); | ||
} catch (exception) { | ||
return NextResponse.json({ error: exception }, { status: 500 }); | ||
} | ||
} | ||
|
||
export { logWorkLeaveHandler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const IS_DEV = process.env.NODE_ENV === 'development'; | ||
export const DEVELOPMENT_DAY = '2019-12-12'; | ||
export const DATE_FORMAT = 'YYYY-MM-DD'; | ||
export const MONTH_DATE_FORMAT = 'YYYY-MM'; | ||
export const IS_DEV = process.env.NODE_ENV === "development"; | ||
export const DEVELOPMENT_DAY = "2019-11-14"; | ||
export const DATE_FORMAT = "YYYY-MM-DD"; | ||
export const MONTH_DATE_FORMAT = "YYYY-MM"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.