mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added add
method for snippets controller
We force the updatedAt here because there is a bug in the original API
This commit is contained in:
parent
e1d2905d21
commit
1abc99cab3
2 changed files with 27 additions and 1 deletions
|
@ -9,6 +9,14 @@ export class SnippetsService {
|
||||||
@Inject('SnippetsRepository') private readonly repository: SnippetsRepository
|
@Inject('SnippetsRepository') private readonly repository: SnippetsRepository
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async create(data: any): Promise<Snippet> {
|
||||||
|
const snippet = Snippet.create(data);
|
||||||
|
|
||||||
|
await this.repository.save(snippet);
|
||||||
|
|
||||||
|
return snippet;
|
||||||
|
}
|
||||||
|
|
||||||
async getOne(id: ObjectID) {
|
async getOne(id: ObjectID) {
|
||||||
return this.repository.getOne(id);
|
return this.repository.getOne(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import {Controller, Get, Param, Query} from '@nestjs/common';
|
import {Body, Controller, Get, Param, Post, Query, UseInterceptors} from '@nestjs/common';
|
||||||
import {SnippetsService} from '../../core/snippets/snippets.service';
|
import {SnippetsService} from '../../core/snippets/snippets.service';
|
||||||
import {SnippetDTO} from './snippet.dto';
|
import {SnippetDTO} from './snippet.dto';
|
||||||
import {Pagination} from '../../common/pagination.type';
|
import {Pagination} from '../../common/pagination.type';
|
||||||
import ObjectID from 'bson-objectid';
|
import ObjectID from 'bson-objectid';
|
||||||
|
import {now} from '../../common/date';
|
||||||
|
import {LocationHeaderInterceptor} from './interceptors/location-header.interceptor';
|
||||||
|
|
||||||
@Controller('snippets')
|
@Controller('snippets')
|
||||||
|
@UseInterceptors(LocationHeaderInterceptor)
|
||||||
export class SnippetsController {
|
export class SnippetsController {
|
||||||
constructor(private readonly service: SnippetsService) {}
|
constructor(private readonly service: SnippetsService) {}
|
||||||
|
|
||||||
|
@ -22,6 +25,21 @@ export class SnippetsController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('')
|
||||||
|
async add(
|
||||||
|
@Body() body: any,
|
||||||
|
@Query('formats') formats?: 'mobiledoc' | 'lexical'
|
||||||
|
): Promise<{snippets: [SnippetDTO]}> {
|
||||||
|
const snippet = await this.service.create({
|
||||||
|
...body.snippets[0],
|
||||||
|
updatedAt: now()
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
snippets: [new SnippetDTO(snippet, {formats})]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Get('')
|
@Get('')
|
||||||
async browse(
|
async browse(
|
||||||
@Query('formats') formats?: 'mobiledoc' | 'lexical',
|
@Query('formats') formats?: 'mobiledoc' | 'lexical',
|
||||||
|
|
Loading…
Add table
Reference in a new issue