import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { SysAgreement } from '../../entity/sysAgreement.entity'; @Injectable() export class SysAgreementService { constructor( @InjectRepository(SysAgreement) private readonly repo: Repository, ) {} async getList() { return this.repo.find({ order: { create_time: 'DESC' }, }); } async getAgreement(key: string) { return this.repo.findOne({ where: { agreement_key: key } }); } async setAgreement(key: string, title: string, content: string) { const existing = await this.repo.findOne({ where: { agreement_key: key } }); if (existing) { await this.repo.update(existing.id, { title, content, update_time: Math.floor(Date.now() / 1000), }); } else { const agreement = this.repo.create({ agreement_key: key, title, content, create_time: Math.floor(Date.now() / 1000), update_time: Math.floor(Date.now() / 1000), }); await this.repo.save(agreement); } } }