mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Removed timezone-related code
refs https://github.com/TryGhost/Arch/issues/99 - The timezone formatting was dropped from the migrated implementation because we do not do the formatting in the legacy API (incorrectly imo). We only do the timezone formatting on Posts API endpoints. - Adding formatting for migrated Snippets API would mean a breaking change, which we don't want to make just yet
This commit is contained in:
parent
df82ab0e5f
commit
200aaacf42
3 changed files with 4 additions and 75 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
})
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue