make sure item name is not empty when creating

master
Lauren Liberda 2021-07-29 00:49:51 +02:00
parent 7788a67a09
commit 88eb19a9ae
1 changed files with 5 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';
import { EntityManager, Repository, TreeRepository } from 'typeorm';
import assert from 'assert';
import { NewItemInput } from './dto/new-item.input';
import { EANService } from './ean/ean.service';
import { Item } from './items.entity';
@ -103,11 +104,15 @@ export class ItemsService {
? (BigInt(highestId) + 1n).toString(10)
: // @ts-ignore input.id must exist here
this.eans.toID(input.id),
name: input.name.trim(),
notes: input.notes ? input.notes.trim() || undefined : undefined,
parent: input.parent
? await this.itemRepository.findOneOrFail(this.eans.toID(input.parent))
: undefined,
});
assert(item.name.length > 0, 'You must provide item name');
await this.itemRepository.save(item);
return item;