Skip to content

Commit

Permalink
chore: ⚡ update ping request to include timezone in response
Browse files Browse the repository at this point in the history
The code changes modify the `app.controller.ts` and `app.service.ts` files in the `be` directory. The changes include updating the `getPing` method in the `AppController` class to accept a `Request` object in addition to the `Response` object. The `getPing` method in the `AppService` class is also updated to accept a `Request` object. The `toZonedTime` function is called with the `req.body['tz']` value or the `process.env['TZ']` value as the timezone parameter.

Based on the recent repository commits, it seems that there have been updates related to the ping functionality and user management.
  • Loading branch information
lehuygiang28 committed Jun 25, 2024
1 parent 795ec2b commit 2ff8f25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apps/be/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Response } from 'express';
import { Controller, Get, Res } from '@nestjs/common';
import { Request, Response } from 'express';
import { Controller, Get, Req, Res } from '@nestjs/common';

import { AppService } from './app.service';

Expand All @@ -8,7 +8,7 @@ export class AppController {
constructor(private readonly appService: AppService) {}

@Get('/ping')
getPing(@Res() res: Response) {
return this.appService.getPing(res);
getPing(@Req() req: Request, @Res() res: Response) {
return this.appService.getPing(req, res);
}
}
12 changes: 8 additions & 4 deletions apps/be/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Response } from 'express';
import { Request, Response } from 'express';
import { Injectable } from '@nestjs/common';
import { toZonedTime, format } from 'date-fns-tz';
import { format } from 'date-fns/format';
import { toZonedTime } from 'date-fns-tz';

@Injectable()
export class AppService {
getPing(res: Response) {
const zonedDate = toZonedTime(new Date(), process.env.TZ || 'Asia/Ho_Chi_Minh');
getPing(req: Request, res: Response) {
const zonedDate = toZonedTime(
new Date(),
req.body['tz'] || process.env['TZ'] || 'Asia/Ho_Chi_Minh',
);
res.json({
message: 'pong',
time: format(zonedDate, 'HH:mm:ss:SSS dd/MM/yyyy'),
Expand Down
11 changes: 7 additions & 4 deletions apps/fe/src/app/api/ping/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { type NextRequest, NextResponse } from 'next/server';
import { toZonedTime, format } from 'date-fns-tz';

import { format } from 'date-fns/format';
import { toZonedTime } from 'date-fns-tz';
export const dynamic = 'force-dynamic';

export async function GET(_req: NextRequest) {
const zonedDate = toZonedTime(new Date(), process.env.TZ || 'Asia/Ho_Chi_Minh');
export async function GET(req: NextRequest) {
const zonedDate = toZonedTime(
new Date(),
req.body['tz'] || process.env['TZ'] || 'Asia/Ho_Chi_Minh',
);
return NextResponse.json({
message: 'pong',
time: format(zonedDate, 'HH:mm:ss:SSS dd/MM/yyyy'),
Expand Down

0 comments on commit 2ff8f25

Please sign in to comment.