Compare commits

..

2 Commits

Author SHA1 Message Date
Ivan Li
7700100a7d build: add pm2 ecosystem config. 2021-05-02 21:11:34 +08:00
Ivan Li
9120332051 fix(articles): 修复返回值不匹配的问题。 2021-05-01 17:17:43 +08:00
5 changed files with 17729 additions and 3047 deletions

14
ecosystem.config.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
apps: [
{
name: 'fennec-be',
script: 'npm',
args: 'run start:prod',
watch: false,
ignore_watch: ['node_modules'],
log_date_format: 'MM-DD HH:mm:ss.SSS Z',
env: {},
max_restarts: 5,
},
],
};

20638
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,16 +26,14 @@ export class ArticlesResolver {
}
@Mutation(() => Article)
updateArticle(
async updateArticle(
@Args('updateArticleInput') updateArticleInput: UpdateArticleInput,
) {
return this.articlesService.update(
updateArticleInput.id,
updateArticleInput,
);
const article = await this.articlesService.findOne(updateArticleInput.id);
return this.articlesService.update(article, updateArticleInput);
}
@Mutation(() => Article)
@Mutation(() => Int)
removeArticle(@Args('id', { type: () => String }) id: string) {
return this.articlesService.remove(id);
}

View File

@ -23,16 +23,20 @@ export class ArticlesService extends BaseDbService<Article> {
}
async findAll() {
return await this.repository.find();
return await this.repository.find({
order: { createdAt: 'DESC' },
});
}
async update(id: string, updateArticleInput: UpdateArticleInput) {
await this.isDuplicateEntityForUpdate(id, updateArticleInput);
return await this.repository.update(id, updateArticleInput);
async update(article: Article, updateArticleInput: UpdateArticleInput) {
await this.isDuplicateEntityForUpdate(article.id, updateArticleInput);
return await this.repository.save(
this.repository.merge(article, updateArticleInput),
);
}
async remove(id: string) {
await this.canRemove([id]);
return await this.repository.softDelete({ id });
return await this.repository.softDelete({ id }).then((d) => d.affected);
}
}

View File

@ -1,8 +1,8 @@
import { CreateArticleInput } from './create-article.input';
import { InputType, Field, Int, PartialType } from '@nestjs/graphql';
import { InputType, Field, PartialType } from '@nestjs/graphql';
@InputType()
export class UpdateArticleInput extends PartialType(CreateArticleInput) {
@Field(() => Int)
@Field(() => String)
id: string;
}