|
@@ -1,14 +1,14 @@
|
|
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify'
|
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify'
|
|
|
import fs from 'fs/promises'
|
|
import fs from 'fs/promises'
|
|
|
import path from 'path'
|
|
import path from 'path'
|
|
|
-import { SenderService } from '../services/sender.service'
|
|
|
|
|
-import { CreateSenderBody, UpdateSenderBody, ListSenderQuery } from '../dto/sender.dto'
|
|
|
|
|
|
|
+import { TgUserService } from '../services/tg-user.service'
|
|
|
|
|
+import { CreateSenderBody, UpdateSenderBody, ListSenderQuery } from '../dto/tg-user.dto'
|
|
|
|
|
|
|
|
-export class SenderController {
|
|
|
|
|
- private senderService: SenderService
|
|
|
|
|
|
|
+export class TgUserController {
|
|
|
|
|
+ private tgUserService: TgUserService
|
|
|
|
|
|
|
|
constructor(app: FastifyInstance) {
|
|
constructor(app: FastifyInstance) {
|
|
|
- this.senderService = new SenderService(app)
|
|
|
|
|
|
|
+ this.tgUserService = new TgUserService(app)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async importFromJson(_: FastifyRequest, reply: FastifyReply) {
|
|
async importFromJson(_: FastifyRequest, reply: FastifyReply) {
|
|
@@ -51,7 +51,7 @@ export class SenderController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const result = await this.senderService.importFromJson(importList)
|
|
|
|
|
|
|
+ const result = await this.tgUserService.importFromJson(importList)
|
|
|
|
|
|
|
|
return reply.send({
|
|
return reply.send({
|
|
|
message: '转换完成',
|
|
message: '转换完成',
|
|
@@ -77,12 +77,12 @@ export class SenderController {
|
|
|
return reply.code(400).send({ message: '缺少必填字段: id' })
|
|
return reply.code(400).send({ message: '缺少必填字段: id' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const existingSender = await this.senderService.findById(id)
|
|
|
|
|
|
|
+ const existingSender = await this.tgUserService.findById(id)
|
|
|
if (existingSender) {
|
|
if (existingSender) {
|
|
|
return reply.code(400).send({ message: '发送者已存在' })
|
|
return reply.code(400).send({ message: '发送者已存在' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const sender = await this.senderService.create(id, dcId, authKey, sessionStr)
|
|
|
|
|
|
|
+ const sender = await this.tgUserService.create(id, dcId, authKey, sessionStr)
|
|
|
|
|
|
|
|
return reply.code(201).send({
|
|
return reply.code(201).send({
|
|
|
message: '创建成功',
|
|
message: '创建成功',
|
|
@@ -99,7 +99,7 @@ export class SenderController {
|
|
|
try {
|
|
try {
|
|
|
const { id } = request.params
|
|
const { id } = request.params
|
|
|
|
|
|
|
|
- const sender = await this.senderService.findById(id)
|
|
|
|
|
|
|
+ const sender = await this.tgUserService.findById(id)
|
|
|
if (!sender) {
|
|
if (!sender) {
|
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
|
}
|
|
}
|
|
@@ -118,7 +118,7 @@ export class SenderController {
|
|
|
try {
|
|
try {
|
|
|
const { page = 0, size = 20, delFlag } = request.query
|
|
const { page = 0, size = 20, delFlag } = request.query
|
|
|
|
|
|
|
|
- const result = await this.senderService.findAll(page, size, delFlag)
|
|
|
|
|
|
|
+ const result = await this.tgUserService.findAll(page, size, delFlag)
|
|
|
|
|
|
|
|
return reply.send(result)
|
|
return reply.send(result)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -136,12 +136,12 @@ export class SenderController {
|
|
|
return reply.code(400).send({ message: '缺少必填字段: id' })
|
|
return reply.code(400).send({ message: '缺少必填字段: id' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const existingSender = await this.senderService.findById(id)
|
|
|
|
|
|
|
+ const existingSender = await this.tgUserService.findById(id)
|
|
|
if (!existingSender) {
|
|
if (!existingSender) {
|
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const updatedSender = await this.senderService.update(id, updateData)
|
|
|
|
|
|
|
+ const updatedSender = await this.tgUserService.update(id, updateData)
|
|
|
|
|
|
|
|
return reply.send({
|
|
return reply.send({
|
|
|
message: '更新成功',
|
|
message: '更新成功',
|
|
@@ -158,12 +158,12 @@ export class SenderController {
|
|
|
try {
|
|
try {
|
|
|
const { id } = request.params
|
|
const { id } = request.params
|
|
|
|
|
|
|
|
- const existingSender = await this.senderService.findById(id)
|
|
|
|
|
|
|
+ const existingSender = await this.tgUserService.findById(id)
|
|
|
if (!existingSender) {
|
|
if (!existingSender) {
|
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await this.senderService.delete(id)
|
|
|
|
|
|
|
+ await this.tgUserService.delete(id)
|
|
|
|
|
|
|
|
return reply.send({
|
|
return reply.send({
|
|
|
message: '删除成功'
|
|
message: '删除成功'
|
|
@@ -179,12 +179,12 @@ export class SenderController {
|
|
|
try {
|
|
try {
|
|
|
const { id } = request.params
|
|
const { id } = request.params
|
|
|
|
|
|
|
|
- const existingSender = await this.senderService.findById(id)
|
|
|
|
|
|
|
+ const existingSender = await this.tgUserService.findById(id)
|
|
|
if (!existingSender) {
|
|
if (!existingSender) {
|
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
return reply.code(404).send({ message: '发送者不存在' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await this.senderService.hardDelete(id)
|
|
|
|
|
|
|
+ await this.tgUserService.hardDelete(id)
|
|
|
|
|
|
|
|
return reply.send({
|
|
return reply.send({
|
|
|
message: '永久删除成功'
|
|
message: '永久删除成功'
|