make sure item name is not empty when creating
This commit is contained in:
parent
7788a67a09
commit
88eb19a9ae
|
@ -1,6 +1,7 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';
|
import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';
|
||||||
import { EntityManager, Repository, TreeRepository } from 'typeorm';
|
import { EntityManager, Repository, TreeRepository } from 'typeorm';
|
||||||
|
import assert from 'assert';
|
||||||
import { NewItemInput } from './dto/new-item.input';
|
import { NewItemInput } from './dto/new-item.input';
|
||||||
import { EANService } from './ean/ean.service';
|
import { EANService } from './ean/ean.service';
|
||||||
import { Item } from './items.entity';
|
import { Item } from './items.entity';
|
||||||
|
@ -103,11 +104,15 @@ export class ItemsService {
|
||||||
? (BigInt(highestId) + 1n).toString(10)
|
? (BigInt(highestId) + 1n).toString(10)
|
||||||
: // @ts-ignore input.id must exist here
|
: // @ts-ignore input.id must exist here
|
||||||
this.eans.toID(input.id),
|
this.eans.toID(input.id),
|
||||||
|
name: input.name.trim(),
|
||||||
|
notes: input.notes ? input.notes.trim() || undefined : undefined,
|
||||||
parent: input.parent
|
parent: input.parent
|
||||||
? await this.itemRepository.findOneOrFail(this.eans.toID(input.parent))
|
? await this.itemRepository.findOneOrFail(this.eans.toID(input.parent))
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert(item.name.length > 0, 'You must provide item name');
|
||||||
|
|
||||||
await this.itemRepository.save(item);
|
await this.itemRepository.save(item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
|
Loading…
Reference in a new issue