feat: add login for plugin
This commit is contained in:
58
src/routes/mark/services/mark.ts
Normal file
58
src/routes/mark/services/mark.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { FindAttributeOptions, Op } from 'sequelize';
|
||||
import { MarkModel } from '../model.ts';
|
||||
|
||||
export class MarkServices {
|
||||
static getList = async (opts: {
|
||||
/** 查询用户的 */
|
||||
uid?: string;
|
||||
query?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
search?: string;
|
||||
markType?: string;
|
||||
sort?: string;
|
||||
};
|
||||
/**
|
||||
* 查询类型
|
||||
* simple: 简单查询 默认
|
||||
*/
|
||||
queryType?: string;
|
||||
}) => {
|
||||
const { uid, query } = opts;
|
||||
const { page = 1, pageSize = 999, search, sort = 'DESC' } = query;
|
||||
const searchWhere = search
|
||||
? {
|
||||
[Op.or]: [{ title: { [Op.like]: `%${search}%` } }, { summary: { [Op.like]: `%${search}%` } }],
|
||||
}
|
||||
: {};
|
||||
if (opts.query?.markType) {
|
||||
searchWhere['markType'] = opts.query.markType;
|
||||
}
|
||||
const attributes: FindAttributeOptions = {
|
||||
exclude: [],
|
||||
};
|
||||
const queryType = opts.queryType || 'simple';
|
||||
if (queryType === 'simple') {
|
||||
// attributes.include = ['id', 'title', 'link', 'summary', 'thumbnail', 'markType', 'tags', 'uid', 'share', 'uname'];
|
||||
attributes.exclude = ['data', 'config', 'cover', 'description'];
|
||||
}
|
||||
const { rows, count } = await MarkModel.findAndCountAll({
|
||||
where: {
|
||||
uid: uid,
|
||||
...searchWhere,
|
||||
},
|
||||
order: [['updatedAt', sort]],
|
||||
attributes: attributes,
|
||||
limit: pageSize,
|
||||
offset: (page - 1) * pageSize,
|
||||
});
|
||||
return {
|
||||
pagination: {
|
||||
current: page,
|
||||
pageSize,
|
||||
total: count,
|
||||
},
|
||||
list: rows,
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user