Skip to content

Commit

Permalink
search bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jesuisstan committed Oct 14, 2024
1 parent 2cef60c commit 09a8ef9
Show file tree
Hide file tree
Showing 11 changed files with 977 additions and 208 deletions.
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,6 @@
"user-deleted-successfully": "User deleted successfully",
"delete": "Delete",
"delete-account": "Delete account",
"are-you-sure": "Are you sure?"
"are-you-sure": "Are you sure?",
"incorrect-age-range": "Incorrect age range"
}
3 changes: 2 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,6 @@
"user-deleted-successfully": "Utilisateur supprimé avec succès",
"delete": "Supprimer",
"delete-account": "Supprimer le compte",
"are-you-sure": "Êtes-vous sûr?"
"are-you-sure": "Êtes-vous sûr?",
"incorrect-age-range": "Plage d'âge incorrecte"
}
7 changes: 4 additions & 3 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"cyclist": "Велосипедист",
"dancer": "Танцор",
"doglover": "Любитель собак",
"early-bird": "Ранний пташка",
"early-bird": "Ранняя пташка",
"eco-friendly": "Экологичный",
"esoteric": "Эзотерический",
"extrovert": "Экстраверт",
Expand Down Expand Up @@ -299,7 +299,7 @@
"settings": "Настройки",
"rating": "Флирт Фактор",
"what-is-this": "Что это?",
"rating-description-message": "Флирт Фактор - это рейтинг, который показывает, насколько Вы привлекательны для других пользователей.\nЧем выше рейтинг, тем больше вероятность найти подходящего партнера.\n\nРейтинг рассчитывается на основе:\n - полноты Вашего профиля,\n - количества фотографий,\n - количества лайков, полученных от других пользователей,\n - Вашей ежедневной активности.\n\nЧем активнее Вы, тем выше будет Ваш рейтинг.\nЧем меньше активности, тем ниже рейтингю",
"rating-description-message": "Флирт Фактор - это рейтинг, который показывает, насколько Вы привлекательны для других пользователей.\nЧем выше рейтинг, тем больше вероятность найти подходящего партнера.\n\nРейтинг рассчитывается на основе:\n - полноты Вашего профиля,\n - количества фотографий,\n - количества лайков, полученных от других пользователей,\n - Вашей ежедневной активности.\n\nЧем активнее Вы, тем выше будет Ваш рейтинг.\nЧем меньше активности, тем ниже рейтинг.",
"theme": "Тема",
"refresh": "Обновить",
"his-her": " (его/её)",
Expand Down Expand Up @@ -424,5 +424,6 @@
"user-deleted-successfully": "Пользователь успешно удалён",
"delete": "Удалить",
"delete-account": "Удалить аккаунт",
"are-you-sure": "Вы уверены?"
"are-you-sure": "Вы уверены?",
"incorrect-age-range": "Неверный диапазон возраста"
}
1,104 changes: 928 additions & 176 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/create-table-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function createTables() {
sex_preferences sex_preferences_enum,
photos TEXT[] DEFAULT '{}' NOT NULL,
complete BOOLEAN DEFAULT false,
rating INT DEFAULT 21,
rating INT DEFAULT 22,
registration_date TIMESTAMP WITH TIME ZONE,
last_action TIMESTAMP WITH TIME ZONE,
online BOOLEAN DEFAULT false,
Expand Down
2 changes: 1 addition & 1 deletion scripts/fake-users-list-confirmed-female.js
Original file line number Diff line number Diff line change
Expand Up @@ -6697,7 +6697,7 @@ module.exports = function (hashedPassword, yesterday) {
sex_preferences: 'women',
registration_date: yesterday.toISOString(),
online: false,
rating: 21,
rating: 22,
biography: 'Environmental activist and nature lover. I love spending time in the wilderness.',
tags: [
'eco-friendly',
Expand Down
30 changes: 15 additions & 15 deletions scripts/fake-users-list-unconfirmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -38,7 +38,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -61,7 +61,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -84,7 +84,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -107,7 +107,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -130,7 +130,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -153,7 +153,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -176,7 +176,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -199,7 +199,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -222,7 +222,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -245,7 +245,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -268,7 +268,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -291,7 +291,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -314,7 +314,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand All @@ -337,7 +337,7 @@ module.exports = function (hashedPassword, yesterday) {
registration_date: yesterday.toISOString(),
confirmed: false,
online: false,
rating: 21,
rating: 22,
complete: false,
sex_preferences: null,
biography: null,
Expand Down
13 changes: 7 additions & 6 deletions src/app/[locale]/(dashboard)/search/advanced/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const AdvancedSearch = () => {
setSuccessMessage('');
if (selectedTags.length === 0) {
setError('error-no-tags-selected');
setIsSidebarOpen(false);
return;
}
setLoading(true);
Expand Down Expand Up @@ -375,10 +376,10 @@ const AdvancedSearch = () => {
name="distance"
placeholder={t(`max`)}
value={distance}
errorMessage="0-9999"
errorMessage="0-9969"
className="-mb-1 w-20"
min={0}
max={9999}
max={9969}
onChange={(e) => setValueOfSearchFilter('distance', Number(e.target.value))}
/>
<p className="self-start pt-2">{t('km')}</p>
Expand All @@ -398,10 +399,10 @@ const AdvancedSearch = () => {
name="age-min"
placeholder={t(`from`)}
value={ageMin}
errorMessage="18-99"
errorMessage="18-169"
className="-mb-1 w-20"
min={18}
max={99}
max={169}
onChange={(e) => setValueOfSearchFilter('age_min', Number(e.target.value))}
/>
<p className="self-start pt-2">{' - '}</p>
Expand All @@ -411,10 +412,10 @@ const AdvancedSearch = () => {
name="age-max"
placeholder={t(`to`)}
value={ageMax}
errorMessage="18-999"
errorMessage="18-169"
className="-mb-1 w-20"
min={18}
max={999}
max={169}
onChange={(e) => setValueOfSearchFilter('age_max', Number(e.target.value))}
/>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export async function POST(req: Request) {
age--;
}

// Define default user sex preferences based on his/her sex (bisexual by default)
let sexPreferences = 'bisexual';
if (sex === 'male') sexPreferences = 'women';
if (sex === 'female') sexPreferences = 'men';

// Validate the birthdate
if (new Date(birthdate) > today) {
return NextResponse.json({ error: 'invalid-birthdate' }, { status: 400 });
Expand Down Expand Up @@ -75,8 +80,8 @@ export async function POST(req: Request) {

// If the email was sent successfully, insert the user into the database
await client.sql`
INSERT INTO users (firstname, lastname, nickname, email, password, birthdate, sex, registration_date, last_action, online, confirmed, service_token)
VALUES (${firstname}, ${lastname}, ${nickname}, ${email}, ${hashedPassword}, ${birthdate}, ${sex}, NOW(), NOW(), false, false, ${confirmationToken});
INSERT INTO users (firstname, lastname, nickname, email, password, birthdate, sex, registration_date, last_action, online, confirmed, service_token, sex_preferences)
VALUES (${firstname}, ${lastname}, ${nickname}, ${email}, ${hashedPassword}, ${birthdate}, ${sex}, NOW(), NOW(), false, false, ${confirmationToken}, ${sexPreferences});
`;

return NextResponse.json({
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/avatar/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export async function DELETE(req: Request): Promise<NextResponse> {
return NextResponse.json({ error: 'failed-to-delete-photo' }, { status: 500 });
}

// Step 3: Remove the photo URL from the user's photos[] array in PostgreSQL. Decrease the user's rating by 5 points, but not below 21.
// Step 3: Remove the photo URL from the user's photos[] array in PostgreSQL. Decrease the user's rating by 5 points, but not below 22.
const currentDate = new Date();
const updateQuery = `
UPDATE users
SET photos = array_remove(photos, $2), last_action = $3, online = true, rating = GREATEST(rating - 5, 21)
SET photos = array_remove(photos, $2), last_action = $3, online = true, rating = GREATEST(rating - 5, 22)
WHERE id = $1
RETURNING id, photos, last_action, online, rating;
`;
Expand Down
8 changes: 8 additions & 0 deletions src/app/api/search/advanced/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export async function POST(request: Request) {
return NextResponse.json({ error: 'user-not-found' }, { status: 404 });
}

if (ageMin < 18) {
return NextResponse.json({ error: 'under-18' }, { status: 403 });
}

if (ageMax < ageMin) {
return NextResponse.json({ error: 'incorrect-age-range' }, { status: 404 });
}

// Update user's last action and set online status to true
const currentDate = new Date().toISOString();
const updateQuery = `
Expand Down

0 comments on commit 09a8ef9

Please sign in to comment.