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';
import Platform = AppsJson.Platform;
import Locale = AppsJson.Locale;
import { ApiParam, ApiProperty } from '@nestjs/swagger';
import { Brackets, SelectQueryBuilder } from 'typeorm';
export interface DepotLike {
platform?: string;
......@@ -23,4 +24,25 @@ export class DepotDto implements DepotLike {
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 {
extraQuery?: (query: SelectQueryBuilder<Build>) => void,
noErrorExit = false
) {
const depotObj = depotDto.toActual;
const query = this.db
.getRepository(Build)
.createQueryBuilder('build')
//.select('build.id', 'id')
//.addSelect('build.checksum', 'checksum')
.innerJoin('build.depot', 'depot')
.innerJoin('depot.app', 'app')
.where('app.id = :id', { id })
.andWhere('app.isDeleted = false')
.andWhere('depot.platform = :platform')
.andWhere('depot.arch = :arch')
.andWhere('depot.locale = :locale')
.andWhere('build.version = :version', { version })
.setParameters(depotObj);
.andWhere(depotDto.getQueryBrackets())
.andWhere('build.version = :version', { version });
if (extraQuery) {
extraQuery(query);
}
......@@ -64,7 +58,6 @@ export class UpdateService extends ConsoleLogger {
extraQuery?: (query: SelectQueryBuilder<Archive>) => void,
noErrorExit = false
) {
const depotObj = depotDto.toActual;
const query = this.db
.getRepository(Archive)
.createQueryBuilder('archive')
......@@ -73,11 +66,8 @@ export class UpdateService extends ConsoleLogger {
.innerJoin('depot.app', 'app')
.where('app.id = :id', { id })
.andWhere('app.isDeleted = false')
.andWhere('depot.platform = :platform')
.andWhere('depot.arch = :arch')
.andWhere('depot.locale = :locale')
.andWhere('build.version = :version', { version })
.setParameters(depotObj);
.andWhere(depotDto.getQueryBrackets())
.andWhere('build.version = :version', { version });
if (extraQuery) {
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