Untitled
unknown
plain_text
2 years ago
1.8 kB
11
Indexable
if (!search) {
const { rows, count } = (await this.seasonRepo.findAndCountAll({
attributes: {
include: [
[
this.sequelize.cast(
this.sequelize.fn('sum', this.sequelize.col('points')),
'integer',
),
'totalPoints',
],
],
},
group: 'Season.id',
include: [
{
model: this.contributionRepo,
required: false,
attributes: [],
},
],
raw: true,
limit,
offset,
subQuery: false,
})) as unknown as {
rows: SeasonWithPoint[]
count: GroupedCountResultItem[]
}
return { data: rows, total: count.length }
}
const { rows, count } = (await this.seasonRepo.findAndCountAll({
where: this.sequelize.where(
this.sequelize.fn(
'to_tsvector',
'english',
this.sequelize.literal(
`coalesce("title", '') || ' ' || coalesce("subTitle", '')`,
),
),
{
[Op.match]: this.sequelize.fn('plainto_tsquery', 'english', search),
},
),
attributes: {
include: [
[
this.sequelize.cast(
this.sequelize.fn('sum', this.sequelize.col('points')),
'integer',
),
'totalPoints',
],
],
},
group: 'Season.id',
include: [
{
model: this.contributionRepo,
required: false,
attributes: [],
},
],
offset,
limit,
subQuery: false,
raw: true,
})) as unknown as {
rows: SeasonWithPoint[]
count: GroupedCountResultItem[]
}
return { data: rows, total: count.length }Editor is loading...