mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Migrate to Sequelize V7
This commit is contained in:
parent
a5a5f4ee2a
commit
a79cc8e172
45 changed files with 329 additions and 422 deletions
|
|
@ -1,14 +1,14 @@
|
|||
//@ts-ignore
|
||||
import { Op, literal } from 'sequelize'
|
||||
import { Op, literal } from '@sequelize/core'
|
||||
import type { Resolvers } from '@/graphql/__generated__/types.generated'
|
||||
|
||||
|
||||
import Category from '@/sequelize/models/category'
|
||||
import Album from '@/sequelize/models/album'
|
||||
|
||||
const fuzzySearch = (words: string[]) => `^${words.map(w => `(?=.*\b${w}\b)`)}.+/i`
|
||||
|
||||
const resolvers: Resolvers = {
|
||||
Query: {
|
||||
searchAlbum: (_, args, { db }) => {
|
||||
searchAlbum: async (_, args, { db }) => {
|
||||
const { title, categories, limit = 10, offset = 0, order = ['createdAt'], mode = 'DESC', status = ['show'] } = args
|
||||
const fuzzyCondition = title ? {
|
||||
[Op.or]: [
|
||||
|
|
@ -18,9 +18,9 @@ const resolvers: Resolvers = {
|
|||
} : {}
|
||||
|
||||
const include = []
|
||||
if (categories) include.push({ model: db.models.category, where: { name: { [Op.in]: categories } } })
|
||||
if (categories) include.push({ model: Category, where: { name: { [Op.in]: categories } } })
|
||||
|
||||
return db.models.album.findAndCountAll({
|
||||
const result = await Album.findAndCountAll({
|
||||
limit, offset,
|
||||
where: {
|
||||
...fuzzyCondition,
|
||||
|
|
@ -29,6 +29,8 @@ const resolvers: Resolvers = {
|
|||
include,
|
||||
order: [literal('`album`.`status` = \'coming\' DESC'), ...order.map(o => [o, mode])]
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
/* searchAlbumByArtist: async (parent, { name, categories, limit, page = 0, order = ['createdAt'], mode = 'DESC', status = ['show'] }, { db }) => {
|
||||
const include = [{ model: db.models.artist, where: { name: { [Op.like]: `%${name}%` } } }]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue