diff --git a/package-lock.json b/package-lock.json index 85d0f4e..2932987 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "body-parser": "^1.20.2", "cors": "^2.8.5", "discreetly-claimcodes": "^1.1.3", - "discreetly-interfaces": "^0.1.25", + "discreetly-interfaces": "^0.1.29", "dotenv": "^16.3.1", "express": "^4.18.2", "express-basic-auth": "^1.2.1", @@ -3470,9 +3470,9 @@ "integrity": "sha512-2QnlhYUPIGLl11XgxIxl6ZKIJZoS2T1ABIHbqjBbec0YYQ2qfWZ7JWH53OZm0mqeO8Dbjon5zK3YNoGiuYJ1Gg==" }, "node_modules/discreetly-interfaces": { - "version": "0.1.25", - "resolved": "https://registry.npmjs.org/discreetly-interfaces/-/discreetly-interfaces-0.1.25.tgz", - "integrity": "sha512-yWKAycHE6mwJbROT+9rQNE5fwYrYmL+VH9ZJfHl2nqt3L++31djQjVgV2xG5/rYBTrkUPnEbFXpzRF1i2pqO7g==", + "version": "0.1.29", + "resolved": "https://registry.npmjs.org/discreetly-interfaces/-/discreetly-interfaces-0.1.29.tgz", + "integrity": "sha512-3R63KkmB+wFKFFzD9DixX3VDoLCYkDuMQZucAItmXbjE+0tFgmrK683a1/WBI9VkBhARip6HsVNrjzaGqdR1Aw==", "dependencies": { "poseidon-lite": "^0.2.0", "rlnjs": "^3.1.4" diff --git a/package.json b/package.json index 6c69be6..9191050 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "body-parser": "^1.20.2", "cors": "^2.8.5", "discreetly-claimcodes": "^1.1.3", - "discreetly-interfaces": "^0.1.25", + "discreetly-interfaces": "^0.1.29", "dotenv": "^16.3.1", "express": "^4.18.2", "express-basic-auth": "^1.2.1", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5254f70..2625dde 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,17 +10,6 @@ datasource db { url = env("DATABASE_URL") } -enum RoomMembershipType { - IDENTITY_LIST - RLN_CONTRACT - BANDADA -} - -enum RoomType { - PUBLIC - PRIVATE - PIXEL -} model Rooms { id String @id @default(auto()) @map("_id") @db.ObjectId @@ -29,7 +18,7 @@ model Rooms { rateLimit Int @default(1000) // epoch length in ms banRateLimit Int @default(1000000) // starting number of epochs banned for userMessageLimit Int @default(1) // per epoch - membershipType RoomMembershipType @default(IDENTITY_LIST) + membershipType String @default("IDENTITY_LIST") identities String[] @default([]) contractAddress String? // RLN_CONTRACT as "chainID:0xADDRESS" bandadaAddress String? // BANDADA as "url:groupID" @@ -37,7 +26,7 @@ model Rooms { messages Messages[] claimCodes ClaimCodes[] @relation(fields: [claimCodeIds], references: [id]) claimCodeIds String[] @default([]) @db.ObjectId - type RoomType @default(PUBLIC) + type String } model ClaimCodes { diff --git a/src/data/db.ts b/src/data/db.ts index cb6055a..32d63bd 100644 --- a/src/data/db.ts +++ b/src/data/db.ts @@ -18,8 +18,8 @@ interface RoomsFromClaimCode { roomIds: string[]; } -export function getRoomByID(id: string): Promise { - return prisma.rooms +export async function getRoomByID(id: string): Promise { + const room = await prisma.rooms .findUnique({ where: { roomId: id @@ -44,6 +44,12 @@ export function getRoomByID(id: string): Promise { console.error(err); throw err; // Add this line to throw the error }); + return new Promise((resolve, reject) => { + if (room) { + resolve(room as RoomI); + } + reject('Room not found'); + }); } export async function getRoomsByIdentity(identity: string): Promise { @@ -108,10 +114,16 @@ export function updateRoomIdentities(idc: string, roomIds: string[]): Promise { - return prisma.rooms.findMany({ +export async function findUpdatedRooms(roomIds: string[]): Promise { + const rooms = await prisma.rooms.findMany({ where: { id: { in: roomIds } } }); + return new Promise((resolve, reject) => { + if (rooms) { + resolve(rooms as RoomI[]); + } + reject('No rooms found'); + }); } /**