新增显示所有邮箱邮件
This commit is contained in:
@@ -6,7 +6,7 @@ import emailService from './email-service';
|
||||
import orm from '../entity/orm';
|
||||
import account from '../entity/account';
|
||||
import { and, asc, eq, gt, inArray, count, sql, ne } from 'drizzle-orm';
|
||||
import { isDel, settingConst } from '../const/entity-const';
|
||||
import {accountConst, isDel, settingConst} from '../const/entity-const';
|
||||
import settingService from './setting-service';
|
||||
import turnstileService from './turnstile-service';
|
||||
import roleService from './role-service';
|
||||
@@ -231,8 +231,18 @@ const accountService = {
|
||||
const { accountId } = params
|
||||
await emailService.physicsDeleteByAccountId(c, accountId)
|
||||
await orm(c).delete(account).where(eq(account.accountId, accountId)).run();
|
||||
}
|
||||
},
|
||||
|
||||
async setAllReceive(c, params, userId) {
|
||||
let a = null
|
||||
const { accountId } = params;
|
||||
const accountRow = await this.selectById(c, accountId);
|
||||
if (accountRow.userId !== userId) {
|
||||
return;
|
||||
}
|
||||
await orm(c).update(account).set({ allReceive: accountConst.allReceive.CLOSE }).where(eq(account.userId, userId)).run();
|
||||
await orm(c).update(account).set({ allReceive: accountRow.allReceive ? 0 : 1 }).where(eq(account.accountId, accountId)).run();
|
||||
}
|
||||
};
|
||||
|
||||
export default accountService;
|
||||
|
||||
@@ -19,17 +19,19 @@ import kvConst from '../const/kv-const';
|
||||
import { t } from '../i18n/i18n'
|
||||
import r2Service from './r2-service';
|
||||
import domainUtils from '../utils/domain-uitls';
|
||||
import account from "../entity/account";
|
||||
|
||||
const emailService = {
|
||||
|
||||
async list(c, params, userId) {
|
||||
|
||||
let { emailId, type, accountId, size, timeSort } = params;
|
||||
let { emailId, type, accountId, size, timeSort, allReceive } = params;
|
||||
|
||||
size = Number(size);
|
||||
emailId = Number(emailId);
|
||||
timeSort = Number(timeSort);
|
||||
accountId = Number(accountId);
|
||||
allReceive = Number(allReceive);
|
||||
|
||||
if (size > 30) {
|
||||
size = 30;
|
||||
@@ -45,6 +47,10 @@ const emailService = {
|
||||
|
||||
}
|
||||
|
||||
if (isNaN(allReceive)) {
|
||||
let accountRow = await accountService.selectById(c, accountId);
|
||||
allReceive = accountRow.allReceive;
|
||||
}
|
||||
|
||||
const query = orm(c)
|
||||
.select({
|
||||
@@ -58,14 +64,18 @@ const emailService = {
|
||||
eq(star.emailId, email.emailId),
|
||||
eq(star.userId, userId)
|
||||
)
|
||||
).leftJoin(
|
||||
account,
|
||||
eq(account.accountId, email.accountId)
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
allReceive ? eq(1,1) : eq(email.accountId, accountId),
|
||||
eq(email.userId, userId),
|
||||
eq(email.accountId, accountId),
|
||||
timeSort ? gt(email.emailId, emailId) : lt(email.emailId, emailId),
|
||||
eq(email.type, type),
|
||||
eq(email.isDel, isDel.NORMAL)
|
||||
eq(email.isDel, isDel.NORMAL),
|
||||
eq(account.isDel, isDel.NORMAL)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -77,23 +87,29 @@ const emailService = {
|
||||
|
||||
const listQuery = query.limit(size).all();
|
||||
|
||||
const totalQuery = orm(c).select({ total: count() }).from(email).where(
|
||||
and(
|
||||
eq(email.accountId, accountId),
|
||||
eq(email.userId, userId),
|
||||
eq(email.type, type),
|
||||
eq(email.isDel, isDel.NORMAL)
|
||||
const totalQuery = orm(c).select({ total: count() }).from(email)
|
||||
.leftJoin(
|
||||
account,
|
||||
eq(account.accountId, email.accountId)
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
allReceive ? eq(1,1) : eq(email.accountId, accountId),
|
||||
eq(email.userId, userId),
|
||||
eq(email.type, type),
|
||||
eq(email.isDel, isDel.NORMAL),
|
||||
eq(account.isDel, isDel.NORMAL)
|
||||
)
|
||||
).get();
|
||||
|
||||
const latestEmailQuery = orm(c).select().from(email).where(
|
||||
and(
|
||||
eq(email.accountId, accountId),
|
||||
allReceive ? eq(1,1) : eq(email.accountId, accountId),
|
||||
eq(email.userId, userId),
|
||||
eq(email.type, type),
|
||||
eq(email.isDel, isDel.NORMAL)
|
||||
))
|
||||
.orderBy(desc(email.emailId)).limit(1).get();
|
||||
.orderBy(desc(email.emailId)).limit(size).get();
|
||||
|
||||
let [list, totalRow, latestEmail] = await Promise.all([listQuery, totalQuery, latestEmailQuery]);
|
||||
|
||||
@@ -445,15 +461,28 @@ const emailService = {
|
||||
},
|
||||
|
||||
async latest(c, params, userId) {
|
||||
let { emailId, accountId } = params;
|
||||
const list = await orm(c).select().from(email).where(
|
||||
and(
|
||||
eq(email.userId, userId),
|
||||
eq(email.isDel, isDel.NORMAL),
|
||||
eq(email.accountId, accountId),
|
||||
eq(email.type, emailConst.type.RECEIVE),
|
||||
gt(email.emailId, emailId)
|
||||
))
|
||||
let { emailId, accountId, allReceive } = params;
|
||||
allReceive = Number(allReceive);
|
||||
|
||||
if (isNaN(allReceive)) {
|
||||
let accountRow = await accountService.selectById(c, accountId);
|
||||
allReceive = accountRow.allReceive;
|
||||
}
|
||||
|
||||
const list = await orm(c).select({...email}).from(email)
|
||||
.leftJoin(
|
||||
account,
|
||||
eq(account.accountId, email.accountId)
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
eq(email.userId, userId),
|
||||
eq(email.isDel, isDel.NORMAL),
|
||||
eq(account.isDel, isDel.NORMAL),
|
||||
allReceive ? eq(1,1) : eq(email.accountId, accountId),
|
||||
eq(email.type, emailConst.type.RECEIVE),
|
||||
gt(email.emailId, emailId)
|
||||
))
|
||||
.orderBy(desc(email.emailId))
|
||||
.limit(20);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user