sequelize#fn TypeScript Examples
The following examples show how to use
sequelize#fn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: lighthouse-db-manager.ts From one-platform with MIT License | 5 votes |
async getLHScores(projectId: string, buildIds: string[]) {
/**
* On passing multiple builds the filter from
* checking as pk is changed to sql in operator
*/
const buildFilter = buildIds.length <= 1 ? buildIds[0] : { [Op.in]: buildIds };
/**
* scores are fetched with
* GROUPING : ["buildId","name"] and value is averaged
* Thus gives LH average score of all properties from DB itself
*/
const stats = await Statistic.findAll({
raw: true,
where: {
projectId,
buildId: buildFilter,
name: {
[Op.or]: Object.keys(DB_SCORE_KEY_TO_LH_KEY),
},
},
group: ['buildId', 'name'],
attributes: ['name', [fn('AVG', col('value')), 'value'], 'buildId'],
});
const lhScoreGroupByBuildId: Record<string, LighthouseScoreType> = {};
stats.forEach((stat) => {
const key = DB_SCORE_KEY_TO_LH_KEY[stat.name];
const score = Math.min(Math.round(stat.value * 100), 100); // convert to percentage
if (lhScoreGroupByBuildId?.[stat.buildId]) {
lhScoreGroupByBuildId[stat.buildId][key] = score;
} else {
lhScoreGroupByBuildId[stat.buildId] = {
[key]: score,
} as LighthouseScoreType;
}
});
return lhScoreGroupByBuildId;
}
Example #2
Source File: index.ts From server with Apache License 2.0 | 5 votes |
public async triggerChannel(channel: Channel,language: string, data: any) {
logger.info("Channel " + channel.identifier + " was triggered, tenant: " + this.tenantId)
if (!language) {
logger.error("Failed to find language for automatic start for channel " + channel.identifier + ", processing stopped, tenant: " + this.tenantId)
return
}
let jobDetails = this.jobMap[channel.identifier+(data?'_sync':'')]
if (jobDetails) {
if (jobDetails[1]) {
logger.warn("Channel " + channel.identifier + " is already running, skip it, tenant: " + this.tenantId)
return
}
jobDetails[1] = true
} else {
jobDetails = [null, true]
this.jobMap[channel.identifier+(data?'_sync':'')] = jobDetails
}
if (!data) {
try {
const whereExpression: any = { tenantId: this.tenantId, channels: {} }
whereExpression.channels[channel.identifier] = { status: 1 }
const result: any = await Item.findAll({
attributes: [
[fn('count', '*'), 'count']
],
where: whereExpression
})
const count = result[0].getDataValue('count')
const handler = this.getHandler(channel)
if (count > 0) {
logger.info("Found " + count + " submitted items for channel " + channel.identifier + ", tenant: " + this.tenantId)
await handler.processChannel(channel, language, data)
} else {
logger.info("Submitted items are not found for channel " + channel.identifier + ", skiping it, tenant: " + this.tenantId)
}
} finally {
jobDetails[1] = false
}
} else {
try {
const handler = this.getHandler(channel)
await handler.processChannel(channel, language, data)
} finally {
jobDetails[1] = false
}
}
}