Commit c1b98d1c authored by nanahira's avatar nanahira

fix generic query

parent b584639b
Pipeline #4773 canceled with stages
in 6 minutes and 36 seconds
...@@ -2,6 +2,7 @@ import { AppsJson } from '../utility/apps-json-type'; ...@@ -2,6 +2,7 @@ import { AppsJson } from '../utility/apps-json-type';
import Platform = AppsJson.Platform; import Platform = AppsJson.Platform;
import Locale = AppsJson.Locale; import Locale = AppsJson.Locale;
import { ApiParam, ApiProperty } from '@nestjs/swagger'; import { ApiParam, ApiProperty } from '@nestjs/swagger';
import { Brackets, SelectQueryBuilder } from 'typeorm';
export interface DepotLike { export interface DepotLike {
platform?: string; platform?: string;
...@@ -23,4 +24,25 @@ export class DepotDto implements DepotLike { ...@@ -23,4 +24,25 @@ export class DepotDto implements DepotLike {
locale: this.locale || 'generic', locale: this.locale || 'generic',
}; };
} }
getFieldQueryBrackets(field: keyof DepotLike) {
const value = this[field];
if (!value || value === 'generic') {
return new Brackets((qb) => {
qb.where(`build.${field} = 'generic`);
});
} else {
return new Brackets((qb) => {
qb.where(`build.${field} = 'generic`).orWhere(`build.${field} = :${field}`, { [field]: value });
});
}
}
getQueryBrackets() {
return new Brackets((qb) => {
qb.where(this.getFieldQueryBrackets('platform'))
.andWhere(this.getFieldQueryBrackets('arch'))
.andWhere(this.getFieldQueryBrackets('locale'));
});
}
} }
...@@ -32,21 +32,15 @@ export class UpdateService extends ConsoleLogger { ...@@ -32,21 +32,15 @@ export class UpdateService extends ConsoleLogger {
extraQuery?: (query: SelectQueryBuilder<Build>) => void, extraQuery?: (query: SelectQueryBuilder<Build>) => void,
noErrorExit = false noErrorExit = false
) { ) {
const depotObj = depotDto.toActual;
const query = this.db const query = this.db
.getRepository(Build) .getRepository(Build)
.createQueryBuilder('build') .createQueryBuilder('build')
//.select('build.id', 'id')
//.addSelect('build.checksum', 'checksum')
.innerJoin('build.depot', 'depot') .innerJoin('build.depot', 'depot')
.innerJoin('depot.app', 'app') .innerJoin('depot.app', 'app')
.where('app.id = :id', { id }) .where('app.id = :id', { id })
.andWhere('app.isDeleted = false') .andWhere('app.isDeleted = false')
.andWhere('depot.platform = :platform') .andWhere(depotDto.getQueryBrackets())
.andWhere('depot.arch = :arch') .andWhere('build.version = :version', { version });
.andWhere('depot.locale = :locale')
.andWhere('build.version = :version', { version })
.setParameters(depotObj);
if (extraQuery) { if (extraQuery) {
extraQuery(query); extraQuery(query);
} }
...@@ -64,7 +58,6 @@ export class UpdateService extends ConsoleLogger { ...@@ -64,7 +58,6 @@ export class UpdateService extends ConsoleLogger {
extraQuery?: (query: SelectQueryBuilder<Archive>) => void, extraQuery?: (query: SelectQueryBuilder<Archive>) => void,
noErrorExit = false noErrorExit = false
) { ) {
const depotObj = depotDto.toActual;
const query = this.db const query = this.db
.getRepository(Archive) .getRepository(Archive)
.createQueryBuilder('archive') .createQueryBuilder('archive')
...@@ -73,11 +66,8 @@ export class UpdateService extends ConsoleLogger { ...@@ -73,11 +66,8 @@ export class UpdateService extends ConsoleLogger {
.innerJoin('depot.app', 'app') .innerJoin('depot.app', 'app')
.where('app.id = :id', { id }) .where('app.id = :id', { id })
.andWhere('app.isDeleted = false') .andWhere('app.isDeleted = false')
.andWhere('depot.platform = :platform') .andWhere(depotDto.getQueryBrackets())
.andWhere('depot.arch = :arch') .andWhere('build.version = :version', { version });
.andWhere('depot.locale = :locale')
.andWhere('build.version = :version', { version })
.setParameters(depotObj);
if (extraQuery) { if (extraQuery) {
extraQuery(query); extraQuery(query);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment