All files / src/services/scan dimension.service.ts

46.15% Statements 6/13
0% Branches 0/2
0% Functions 0/3
36.36% Lines 4/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x 1x   1x         1x                                                                                                    
import {bind, BindingScope} from '@loopback/core';
import {repository} from '@loopback/repository';
import {HttpErrors} from '@loopback/rest';
import {DimensionRepository} from '@logchain/repositories/scan/dimension.repository';
 
@bind({
  scope: BindingScope.TRANSIENT,
})
export class DimensionService {
  constructor(
    @repository(DimensionRepository)
    public dimensionRepo: DimensionRepository,
  ) {}
 
  /**
   * CREATE
   */
  async create(data: {
    length: number;
 
    width: number;
 
    height: number;
  }) {
    const displayText =
      `${data.length}x${data.width}x${data.height}`;
 
    const existed = await this.dimensionRepo.findOne({
      where: {
        display_text: displayText,
      },
    });
 
    if (existed) {
      return existed;
    }
 
    return this.dimensionRepo.create({
      length: data.length,
 
      width: data.width,
 
      height: data.height,
 
      display_text: displayText,
 
      created_at: new Date(),
    });
  }
 
  /**
   * GET ALL
   */
  async getAll() {
    return this.dimensionRepo.find({
      order: ['created_at DESC'],
    });
  }
}