case insensitive names

This commit is contained in:
keyan 2021-09-02 17:22:00 -05:00
parent bf6b2befde
commit 38ba31f2b4
4 changed files with 40 additions and 30 deletions

View File

@ -44,38 +44,38 @@ export default {
let notifications = await models.$queryRaw(`
SELECT ${ITEM_FIELDS}, "Item".created_at as "sortTime", NULL as "earnedSats",
false as mention
From "Item"
JOIN "Item" p ON "Item"."parentId" = p.id
WHERE p."userId" = $1
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
false as mention
FROM "Item"
JOIN "Item" p ON "Item"."parentId" = p.id
WHERE p."userId" = $1
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
UNION ALL
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as "sortTime",
sum(subquery.sats) as "earnedSats", false as mention
FROM
(SELECT ${ITEM_FIELDS}, "Vote".created_at as voted_at, "Vote".sats,
ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
ROW_NUMBER() OVER(PARTITION BY "Item".id ORDER BY "Vote".created_at) as island
FROM "Vote"
JOIN "Item" on "Vote"."itemId" = "Item".id
WHERE "Vote"."userId" <> $1
AND "Vote".created_at <= $2
AND "Vote".boost = false
AND "Item"."userId" = $1) subquery
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island ORDER BY max(subquery.voted_at) desc)
sum(subquery.sats) as "earnedSats", false as mention
FROM
(SELECT ${ITEM_FIELDS}, "Vote".created_at as voted_at, "Vote".sats,
ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
ROW_NUMBER() OVER(PARTITION BY "Item".id ORDER BY "Vote".created_at) as island
FROM "Vote"
JOIN "Item" on "Vote"."itemId" = "Item".id
WHERE "Vote"."userId" <> $1
AND "Vote".created_at <= $2
AND "Vote".boost = false
AND "Item"."userId" = $1) subquery
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island ORDER BY max(subquery.voted_at) desc)
UNION ALL
(SELECT ${ITEM_FIELDS}, "Mention".created_at as "sortTime", NULL as "earnedSats",
true as mention
FROM "Mention"
JOIN "Item" on "Mention"."itemId" = "Item".id
JOIN "Item" p on "Item"."parentId" = p.id
WHERE "Mention"."userId" = $1
AND "Mention".created_at <= $2
AND "Item"."userId" <> $1
AND p."userId" <> $1)
ORDER BY "sortTime" DESC
OFFSET $3
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
true as mention
FROM "Mention"
JOIN "Item" on "Mention"."itemId" = "Item".id
JOIN "Item" p on "Item"."parentId" = p.id
WHERE "Mention"."userId" = $1
AND "Mention".created_at <= $2
AND "Item"."userId" <> $1
AND p."userId" <> $1)
ORDER BY "sortTime" DESC
OFFSET $3
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
notifications = notifications.map(n => {
n.item = { ...n }

View File

@ -14,7 +14,7 @@ export default {
throw new AuthenticationError('you must be logged in')
}
return me.name === name || !(await models.user.findUnique({ where: { name } }))
return me.name?.toUpperCase() === name?.toUpperCase() || !(await models.user.findUnique({ where: { name } }))
},
recentlyStacked: async (parent, args, { models, me }) => {
if (!me) {

View File

@ -0,0 +1,10 @@
/*
Warnings:
- A unique constraint covering the columns `[name]` on the table `users` will be added. If there are existing duplicate values, this will fail.
*/
CREATE EXTENSION IF NOT EXISTS citext;
-- AlterTable
ALTER TABLE users ALTER COLUMN name TYPE citext;

View File

@ -14,7 +14,7 @@ model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
name String? @unique
name String? @unique @db.Citext
email String? @unique
emailVerified DateTime? @map(name: "email_verified")
image String?