新增邮箱列表置顶排序
This commit is contained in:
@@ -5,7 +5,7 @@ import userService from './user-service';
|
||||
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 { and, asc, eq, gt, inArray, count, sql, ne, or, lt, desc } from 'drizzle-orm';
|
||||
import {accountConst, isDel, settingConst} from '../const/entity-const';
|
||||
import settingService from './setting-service';
|
||||
import turnstileService from './turnstile-service';
|
||||
@@ -105,10 +105,11 @@ const accountService = {
|
||||
|
||||
list(c, params, userId) {
|
||||
|
||||
let { accountId, size } = params;
|
||||
let { accountId, size, lastSort } = params;
|
||||
|
||||
accountId = Number(accountId);
|
||||
size = Number(size);
|
||||
lastSort = Number(lastSort);
|
||||
|
||||
if (size > 30) {
|
||||
size = 30;
|
||||
@@ -117,12 +118,24 @@ const accountService = {
|
||||
if (!accountId) {
|
||||
accountId = 0;
|
||||
}
|
||||
|
||||
if(Number.isNaN(lastSort)) {
|
||||
lastSort = 9999999999;
|
||||
}
|
||||
|
||||
return orm(c).select().from(account).where(
|
||||
and(
|
||||
eq(account.userId, userId),
|
||||
eq(account.isDel, isDel.NORMAL),
|
||||
gt(account.accountId, accountId)))
|
||||
.orderBy(asc(account.accountId))
|
||||
or(
|
||||
lt(account.sort, lastSort),
|
||||
and(
|
||||
eq(account.sort, lastSort),
|
||||
gt(account.accountId, accountId)
|
||||
)
|
||||
))
|
||||
)
|
||||
.orderBy(desc(account.sort), asc(account.accountId))
|
||||
.limit(size)
|
||||
.all();
|
||||
},
|
||||
@@ -242,6 +255,16 @@ const accountService = {
|
||||
}
|
||||
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();
|
||||
},
|
||||
|
||||
async setAsTop(c, params, userId) {
|
||||
const { accountId } = params;
|
||||
console.log(accountId);
|
||||
const userRow = await userService.selectById(c, userId);
|
||||
const mainAccountRow = await accountService.selectByEmailIncludeDel(c, userRow.email);
|
||||
let mainSort = mainAccountRow.sort === 0 ? 2 : mainAccountRow.sort + 1;
|
||||
await orm(c).update(account).set({ sort: mainSort }).where(eq(account.email, userRow.email )).run();
|
||||
await orm(c).update(account).set({ sort: mainSort - 1 }).where(and(eq(account.accountId, accountId),eq(account.userId,userId))).run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -457,12 +457,12 @@ const emailService = {
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
gt(email.emailId, emailId),
|
||||
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)
|
||||
eq(email.type, emailConst.type.RECEIVE)
|
||||
))
|
||||
.orderBy(desc(email.emailId))
|
||||
.limit(20);
|
||||
|
||||
Reference in New Issue
Block a user