make sure item name is not empty when creating
parent
7788a67a09
commit
88eb19a9ae
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue