order: [
[
Sequelize.literal(
"(SELECT MAX(`goals`.`filtered_currency`) FROM `goals` WHERE `goals`.`offerId` = `offer`.`id`)"
),
order,
],
],
const Offer = sequelize.define("offer", {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
id_api: {
type: DataTypes.INTEGER,
allowNull: false,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
image: {
type: DataTypes.STRING,
allowNull: true,
},
partner: {
type: DataTypes.STRING,
allowNull: false,
},
});
const Goal = sequelize.define("goal", {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
type: { type: DataTypes.STRING, allowNull: true },
price: { type: DataTypes.INTEGER, defaultValue: 0 },
filtered_currency: { type: DataTypes.FLOAT, defaultValue: 0 },
currency_price: { type: DataTypes.STRING, allowNull: true },
offerId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: "offers",
key: "id",
},
},
});
Offer.hasMany(Goal, { foreignKey: "offerId", as: "goals" });
Goal.belongsTo(Offer, { foreignKey: "offerId" });
const offers = await Offer.findAll({
attributes: [
"id",
"id_api",
"title",
"image",
"partner",
[
sequelize.fn("MAX", sequelize.col("goals.filtered_currency")),
"max_filtered_currency",
],
],
include: [
{
model: Goal,
as: "goals",
attributes: ["filtered_currency"],
},
],
group: ["offer.id"],
offset: convertNegativeToZero(offsetNum),
limit: perPageNum,
order: [[sequelize.literal("max_filtered_currency"), "DESC"]],
});
const offers = await Offer.findAndCountAll({
offset: convertNegativeToZero(offsetNum),
limit: perPageNum,
distinct: true,
attributes: ["id", "title", "image", "partner"],
where: itemsPartners,
include: [
{
model: Goal,
as: "goals",
attributes: ["type", "price", "currency_price", "filtered_currency"],
},
],
order: [
[
Sequelize.literal(
"(SELECT MAX(`goals`.`filtered_currency`) FROM `goals` WHERE `goals`.`offerId` = `offer`.`id`)"
),
DESC,
],
],
});
register_post_type('auctions', array(
'label' => null,
'labels' => array(
'add_new' => __('Добавить новый', 'auctions'),
'name' => __( '[:ru]Аукционы[:eng]Auctions[:]' ), // основное название для типа записи
'singular_name' =>__('Аукцион', 'auctions'), // название для одной записи этого типа
'menu_name' => __( '[:ru]Аукционы[:eng]Auctions[:]' ),// название меню
),
'description' => '',
'menu_icon' => 'dashicons-image-crop',
'public' => true,
'show_in_nav_menus' => true,
'supports' => array('title','editor', 'thumbnail'),
'taxonomies' => array( 'auctions_category' ),
'has_archive' => true,
'rewrite' => true,
'query_var' => true,
) );
register_post_type('lots', array(
'label' => null,
'labels' => array(
'add_new' => 'Добавить новый',
'name' => 'Лоты', // основное название для типа записи
'singular_name' => 'Лот', // название для одной записи этого типа
'menu_name' => 'Лоты', // название меню
),
'description' => '',
'menu_icon' => 'dashicons-tag',
'public' => true,
'show_in_nav_menus' => true,
'supports' => array('title','editor', 'thumbnail'),
'taxonomies' => array( 'lots_category' ),
'has_archive' => true,
'rewrite' => true,
'query_var' => true,
) );