Compare commits

..

No commits in common. "9daca90d6b68bb114ee20684b4f506230d1c8c8e" and "f390e2a8c34a608a791f23f08efb63b2c2aeccc7" have entirely different histories.

6 changed files with 14 additions and 52 deletions

View file

@ -1,8 +1,7 @@
import { Injectable } from '@nestjs/common';
import { DataSource, ILike, Repository } from 'typeorm';
import { DataSource, Repository } from 'typeorm';
import { Merchant } from './entities/merchant.entity';
import { UpdateMerchantDto } from './dto/update-merchant.dto';
import { GetMerchantFilters } from './merchants.controller';
@Injectable()
export class MerchantDataService {
@ -12,14 +11,8 @@ export class MerchantDataService {
this.merchants = this.dataSource.getRepository(Merchant);
}
public async get(filters: GetMerchantFilters): Promise<Merchant[]> {
const idFilters = filters.ids?.map(id => { return { id }}) ?? [];
const nameFilters = filters.merchants?.map(tag => { return { name: ILike('%' + tag + '%') }}) ?? [];
return await this.merchants.find({
where: [...idFilters, ...nameFilters],
order: { name: filters.sort === 'desc' ? 'desc' : 'asc' },
});
public async getAll(): Promise<Merchant[]> {
return await this.merchants.find();
}
public async getById(id: string): Promise<Merchant | null> {

View file

@ -6,7 +6,6 @@ import {
Delete,
Body,
Param,
Query,
HttpCode,
HttpStatus,
NotFoundException,
@ -24,12 +23,8 @@ export class MerchantsController {
@Get()
@HttpCode(HttpStatus.OK)
public async find(@Query() filters: GetMerchantFilters): Promise<Merchant[]> {
const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : [];
const merchants = Array.isArray(filters.merchants) ? filters.merchants : filters.merchants ? [filters.merchants] : [];
const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc';
return await this.merchantsService.find({ ids, merchants, sort });
public async findAll(): Promise<Merchant[]> {
return await this.merchantsService.findAll();
}
@Get(':id')
@ -78,9 +73,3 @@ export class MerchantsController {
return await this.merchantsService.remove(id);
}
}
export interface GetMerchantFilters {
ids?: string[];
merchants?: string[];
sort?: 'asc' | 'desc';
}

View file

@ -3,14 +3,13 @@ import { CreateMerchantDto } from './dto/create-merchant.dto';
import { UpdateMerchantDto } from './dto/update-merchant.dto';
import { MerchantDataService } from './merchant-data.service';
import { Merchant } from './entities/merchant.entity';
import { GetMerchantFilters } from './merchants.controller';
@Injectable()
export class MerchantsService {
public constructor(private merchantDataService: MerchantDataService) { }
public async find(filters: GetMerchantFilters): Promise<Merchant[]> {
return await this.merchantDataService.get(filters);
public async findAll(): Promise<Merchant[]> {
return await this.merchantDataService.getAll();
}
public async findById(id: string): Promise<Merchant> {

View file

@ -1,8 +1,7 @@
import { Injectable } from '@nestjs/common';
import { DataSource, ILike, Repository } from 'typeorm';
import { DataSource, Repository } from 'typeorm';
import { Tag } from './entities/tag.entity';
import { UpdateTagDto } from './dto/update-tag.dto';
import { GetTagFilters } from './tags.controller';
@Injectable()
export class TagDataService {
@ -12,14 +11,8 @@ export class TagDataService {
this.tags = this.dataSource.getRepository(Tag);
}
public async get(filters: GetTagFilters): Promise<Tag[]> {
const idFilters = filters.ids?.map(id => { return { id }}) ?? [];
const nameFilters = filters.tags?.map(tag => { return { name: ILike('%' + tag + '%') }}) ?? [];
return await this.tags.find({
where: [...idFilters, ...nameFilters],
order: { name: filters.sort === 'desc' ? 'desc' : 'asc' },
});
public async getAll(): Promise<Tag[]> {
return await this.tags.find();
}
public async getById(id: string): Promise<Tag | null> {

View file

@ -6,7 +6,6 @@ import {
Delete,
Body,
Param,
Query,
HttpCode,
HttpStatus,
BadRequestException,
@ -24,12 +23,8 @@ export class TagsController {
@Get()
@HttpCode(HttpStatus.OK)
public async find(@Query() filters: GetTagFilters): Promise<Tag[]> {
const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : [];
const tags = Array.isArray(filters.tags) ? filters.tags : filters.tags ? [filters.tags] : [];
const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc';
return await this.tagsService.find({ ids, tags, sort });
public async findAll(): Promise<Tag[]> {
return await this.tagsService.findAll();
}
@Get(':id')
@ -78,9 +73,3 @@ export class TagsController {
return await this.tagsService.remove(id);
}
}
export interface GetTagFilters {
ids?: string[];
tags?: string[];
sort?: 'asc' | 'desc';
}

View file

@ -3,14 +3,13 @@ import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { TagDataService } from './tag-data.service';
import { Tag } from './entities/tag.entity';
import { GetTagFilters } from './tags.controller';
@Injectable()
export class TagsService {
public constructor(private tagDataService: TagDataService) { }
public async find(filters: GetTagFilters): Promise<Tag[]> {
return await this.tagDataService.get(filters);
public async findAll(): Promise<Tag[]> {
return await this.tagDataService.getAll();
}
public async findById(id: string): Promise<Tag> {