Skip to content

Anime-Soul/backend-nestjs

Repository files navigation

update nestjs

nest update -f -t latest
// https://stackoverflow.com/questions/59645009/how-to-return-only-some-columns-of-a-relations-with-typeorm

const { sum, count } = await this.AppraisalRepository.createQueryBuilder('a')
  .where('bindPostId = :id', { id })
  .select('SUM(a.rate)', 'sum')
  .addSelect('COUNT(a.id)', 'count')
  .getRawOne<{ sum: string; count: string }>();

await rep
  .select(['p', 'u', 't', 'c', 'a.rate'])
  .leftJoin('p.creator', 'u')
  .leftJoin('p.categories', 'c')
  .leftJoin('p.tags', 't')
  .leftJoin('p.appraisals', 'a') //TODO: 只查询 rate 字段
  .loadRelationCountAndMap('p.commentCount', 'p.comments', 'cm')
  .skip(offset * limit)
  .take(limit)
  .orderBy('p.createdAt', 'DESC')
  .getMany();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published