21 lines
825 B
JavaScript
21 lines
825 B
JavaScript
import { Op, Sequelize } from 'sequelize';
|
|
|
|
// One calendar day is one game year. Only the minimum age restricts age;
|
|
// neither the age difference nor the date the character was created matters.
|
|
export function buildPartnerCandidateQuery({ characterId, gender, regionId, titleId, minimumAge, now = new Date() }) {
|
|
const minimumAgeCutoff = new Date(now);
|
|
minimumAgeCutoff.setHours(0, 0, 0, 0);
|
|
minimumAgeCutoff.setDate(minimumAgeCutoff.getDate() - minimumAge + 1);
|
|
return {
|
|
where: {
|
|
id: { [Op.ne]: characterId },
|
|
gender: { [Op.ne]: gender },
|
|
regionId,
|
|
birthdate: { [Op.lt]: minimumAgeCutoff },
|
|
titleOfNobility: { [Op.between]: [titleId - 1, titleId + 1] },
|
|
},
|
|
order: Sequelize.literal('random()'),
|
|
limit: 5,
|
|
};
|
|
}
|