Skip to content

Commit 02bacd4

Browse files
committed
added current_user_rating to level route
1 parent 74448a9 commit 02bacd4

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

backend/server.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import postgres from "postgres";
22
import { authenticate, type authResponse, getCookies } from "./auth.ts";
33

4-
const STATIC_DIR = "dist";
4+
// const STATIC_DIR = "dist"
5+
const STATIC_DIR = "frontend";
56

67
async function serveFile(req: Request, filePath: string) {
78
let theme = "cream";
@@ -420,8 +421,17 @@ const server = Bun.serve({
420421
returnedJson.owned =
421422
returnedJson.owner == authentication?.user || false;
422423

423-
const username =
424-
await sql`select username from users where id = ${returnedJson.owner}`;
424+
let currentRating = null
425+
426+
if (authentication?.user) {
427+
const rating = await sql`select thumbs_up from ratings where user_id = ${authentication.user} AND level_id = ${levelId}`
428+
console.log(rating)
429+
currentRating = rating !== [] ? rating[0].thumbs_up : null
430+
}
431+
432+
returnedJson.current_user_rating = currentRating
433+
434+
const username = await sql`select username from users where id = ${returnedJson.owner}`;
425435
if (username[0]) {
426436
returnedJson.username = username[0].username;
427437
}

docs/level-data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ RLE, or run length encoding compresses data by storing runs of numbers instead o
4747

4848
`[0, 0, 0, 0, 0, 5, 6, 1, 1, 1, 0]`
4949

50-
RLE would encode that as:
50+
RE would encode that as:
5151

5252
`[[0, 5], 5, 6, [1, 3], 0]`
5353

5454
This takes a level down to about 4KB.
5555

56-
**Layer Types**
56+
### **Layer Types**
5757

5858
`"tileLayer"` - stores the tileIds of every single block in the level
5959

todo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@
3232

3333
**Documentation**
3434

35-
- level data
3635
- trigger storage

0 commit comments

Comments
 (0)