Files
2026-04-21 22:34:39 +08:00

128 lines
5.4 KiB
JavaScript

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TeamService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const team_relation_model_1 = require("../../../model/team_relation.model");
const api_1 = require("../../common/api");
const repository_help_1 = require("../../common/util/repository_help");
const help_1 = require("../../common/util/help");
const user_sign_in_model_1 = require("../../../model/user_sign_in.model");
let TeamService = class TeamService {
teamRelationModel;
userSignInModel;
constructor(teamRelationModel, userSignInModel) {
this.teamRelationModel = teamRelationModel;
this.userSignInModel = userSignInModel;
}
async getTeamStats(userId) {
const userRelation = await this.teamRelationModel.findOne({
where: { userId },
});
if (!userRelation) {
return api_1.Api.error('用户团队关系不存在');
}
const directChildrenCount = await this.teamRelationModel.count({
where: { parentId: userId },
});
const grandchildrenCount = await this.teamRelationModel.count({
where: { grandparentId: userId },
});
const greatGrandchildrenCount = await this.teamRelationModel.count({
where: { greatGrandparentId: userId },
});
return api_1.Api.success({
directChildrenCount,
grandchildrenCount,
greatGrandchildrenCount,
});
}
async getTodayNewStats(userId) {
const todayStr = help_1.Help.formatDate(new Date(), 'YYYY-MM-DD');
const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);
const tomorrowStr = help_1.Help.formatDate(tomorrow, 'YYYY-MM-DD');
const directChildrenCount = await this.teamRelationModel.count({
where: {
parentId: userId,
createTime: (0, typeorm_2.Between)(todayStr, tomorrowStr),
},
});
const grandchildrenCount = await this.teamRelationModel.count({
where: {
grandparentId: userId,
createTime: (0, typeorm_2.Between)(todayStr, tomorrowStr),
},
});
const greatGrandchildrenCount = await this.teamRelationModel.count({
where: {
greatGrandparentId: userId,
createTime: (0, typeorm_2.Between)(todayStr, tomorrowStr),
},
});
return {
directChildrenCount,
grandchildrenCount,
greatGrandchildrenCount,
};
}
async getTodayNewStatsSimple(userId) {
const stats = await this.getTodayNewStats(userId);
return api_1.Api.success(stats);
}
async getTeamMembers(userId, dto) {
let whereCondition = {};
if (dto.level === 1) {
whereCondition = { parentId: userId };
}
else if (dto.level === 2) {
whereCondition = { grandparentId: userId };
}
else if (dto.level === 3) {
whereCondition = { greatGrandparentId: userId };
}
const { data, total } = await repository_help_1.RepositoryHelp.findPaginated(this.teamRelationModel, dto, {
where: whereCondition,
order: { createTime: 'DESC' },
relations: ['user'],
});
const userIds = data.map((r) => r.userId);
let signInRecords = [];
if (userIds.length > 0) {
signInRecords = await this.userSignInModel.find({
where: { userId: (0, typeorm_2.Between)(Math.min(...userIds), Math.max(...userIds)) },
});
}
const members = data.map((relation) => {
const signIn = signInRecords.find((r) => r.userId === relation.userId);
return {
...relation.user,
level: relation.level,
createTime: relation.createTime,
signIn,
};
});
return api_1.Api.pagination(members, total);
}
};
exports.TeamService = TeamService;
exports.TeamService = TeamService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, typeorm_1.InjectRepository)(team_relation_model_1.TeamRelationModel)),
__param(1, (0, typeorm_1.InjectRepository)(user_sign_in_model_1.UserSignInModel)),
__metadata("design:paramtypes", [typeorm_2.Repository,
typeorm_2.Repository])
], TeamService);
//# sourceMappingURL=team.service.js.map