Skip to content

Instantly share code, notes, and snippets.

@david-mart
Created November 18, 2020 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-mart/07c26e8f9a1e9d9685030ace2980f7df to your computer and use it in GitHub Desktop.
Save david-mart/07c26e8f9a1e9d9685030ace2980f7df to your computer and use it in GitHub Desktop.
const includeTags = (ids) => `exists (
select *
from jobtag jt
where jt.job_id = job.id
and shop_tag_id in (${ids})
group by job_id
having count(*) >= ${ids.length}
)`;
const excludeTags = (ids) => `not exists(
select *
from jobtag jt
where jt.job_id = job.id
and shop_tag_id in (${ids})
)`;
const includeTaxes = (ids) => `exists(select *
from jobtax jt
where jt.job_id = job.id
and jt.shop_tax_id in (${ids})
group by job_id
having count(*) >= ${ids.length}
)`;
const excludeTaxes = (ids) => `not exists(select *
from jobtax jt
where jt.job_id = job.id
and jt.shop_tax_id in (${ids})
)`;
const include_tags = [4646];
const exclude_tags = [4648];
const include_taxes = [3029, 3030];
const exclude_taxes = [3028];
Logger.Info(
await GbOrm.job.findAll({
attributes: ['id'],
limit: 100,
where: {
includeTags: literal(includeTags(include_tags)),
excludeTags: literal(excludeTags(exclude_tags)),
includeTaxes: literal(includeTaxes(include_taxes)),
excludeTaxes: literal(excludeTaxes(exclude_taxes)),
shop_id: 1013,
},
}),
true,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment