diff --git a/ghost/ghost/src/http/controllers/browse-snippet.dto.ts b/ghost/ghost/src/http/controllers/browse-snippet.dto.ts index 1aedcdf861..8b2ebb2355 100644 --- a/ghost/ghost/src/http/controllers/browse-snippet.dto.ts +++ b/ghost/ghost/src/http/controllers/browse-snippet.dto.ts @@ -9,7 +9,7 @@ export class BrowseSnippetDTO { created_at: Date; updated_at: Date|null; - constructor(data: Snippet, options: {timezone: string, formats?: 'mobiledoc'|'lexical'}) { + constructor(data: Snippet, options: {formats?: 'mobiledoc'|'lexical'}) { this.id = data.id; this.name = data.name; diff --git a/ghost/ghost/src/http/controllers/snippets.controller.ts b/ghost/ghost/src/http/controllers/snippets.controller.ts index 77f75f1c67..5d603109f5 100644 --- a/ghost/ghost/src/http/controllers/snippets.controller.ts +++ b/ghost/ghost/src/http/controllers/snippets.controller.ts @@ -1,23 +1,10 @@ -import {Controller, Get, Inject, Query} from '@nestjs/common'; +import {Controller, Get, Query} from '@nestjs/common'; import {SnippetsService} from '../../core/snippets/snippets.service'; import {BrowseSnippetDTO} from './browse-snippet.dto'; -import {ISettingsCache} from '../../common/settings-cache.interface'; @Controller('snippets') export class SnippetsController { - timezone: string; - - constructor( - private readonly catsService: SnippetsService, - @Inject('settings') private readonly settings: ISettingsCache - ) { - const timezoneValue = this.settings.get('timezone'); - if (timezoneValue === null) { - throw new Error('Timezone setting is required'); - } else { - this.timezone = timezoneValue; - } - } + constructor(private readonly catsService: SnippetsService) {} @Get('') async browse(@Query('formats') formats?: 'mobiledoc' | 'lexical', @Query('filter') filter?: string): Promise<{snippets: BrowseSnippetDTO[], meta: any}> { @@ -25,7 +12,7 @@ export class SnippetsController { filter }); - const snippetDTOs = snippets.map(snippet => new BrowseSnippetDTO(snippet, {timezone: this.timezone, formats})); + const snippetDTOs = snippets.map(snippet => new BrowseSnippetDTO(snippet, {formats})); return { snippets: snippetDTOs, diff --git a/ghost/ghost/src/nestjs/interceptors/timezone.interceptor.ts b/ghost/ghost/src/nestjs/interceptors/timezone.interceptor.ts deleted file mode 100644 index 590229ea4d..0000000000 --- a/ghost/ghost/src/nestjs/interceptors/timezone.interceptor.ts +++ /dev/null @@ -1,58 +0,0 @@ -import {CallHandler, ExecutionContext, Inject, Injectable, NestInterceptor} from '@nestjs/common'; -import {ISettingsCache} from '../../common/settings-cache.interface'; -import {map} from 'rxjs/operators'; - -@Injectable() -export class TimezoneInterceptor implements NestInterceptor { - constructor( - @Inject('settings') private readonly settings: ISettingsCache - ) {} - - format(date: string) { - // TODO Use moment-timezone or smth to format the date - return date; - } - - intercept(context: ExecutionContext, next: CallHandler) { - return next.handle().pipe(map((data: unknown) => { - if (data === null) { - return data; - } - if (typeof data !== 'object') { - return data; - } - const keys = Object.keys(data); - - let field: string; - if (keys.length === 1) { - field = keys[0]; - } else if (keys.length === 2) { - const filtered = keys.filter(key => key !== 'meta'); - if (filtered.length !== 1) { - return data; - } - field = filtered[0]; - } else { - return data; - } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const objects = (data as any)[field]; - - return { - ...data, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [field]: objects.map((object: any) => { - ['created_at', 'updated_at', 'published_at'].forEach( - (key) => { - if (object[key]) { - object[key] = this.format(object[key]); - } - } - ); - return object; - }) - }; - })); - } -}