Skip to content

Commit

Permalink
Fix wheel create and update timestamps being saved as numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
gomander committed Jan 12, 2024
1 parent 1bce965 commit e00cf73
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"canvas-confetti": "^1.9.2",
"postcss": "^8.4.33",
"svelte": "^4.2.8",
"svelte-check": "^3.6.2",
"svelte-check": "^3.6.3",
"svelte-dnd-action": "^0.9.38",
"tailwindcss": "^3.4.1",
"tslib": "^2.6.2",
Expand All @@ -41,7 +41,7 @@
"dependencies": {
"@floating-ui/dom": "^1.5.4",
"@napi-rs/canvas": "^0.1.44",
"@sveltejs/kit": "^2.3.0",
"@sveltejs/kit": "^2.3.2",
"firebase": "^10.7.1",
"firebase-admin": "^11.11.1",
"firebase-frameworks": "^0.11.1",
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions src/lib/server/FirebaseAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const saveWheel = async (
path,
uid,
visibility,
created: Date.now(),
created: new Date(),
updated: null,
title: wheel.config.title,
views: 0
Expand All @@ -89,33 +89,31 @@ export const updateWheel = async (
uid: string,
visibility?: WheelVisibility
) => {
const wheelMetaDoc = db.doc(`wheel-meta/${path}`)
const wheelMetaSnap = await wheelMetaDoc.get()
if (!wheelMetaSnap.exists) {
const metaDoc = db.doc(`wheel-meta/${path}`)
const metaSnap = await metaDoc.get()
if (!metaSnap.exists) {
return null
}
const wheelMeta = wheelMetaSnap.data() as ApiWheelMeta
if (wheelMeta.uid !== uid) {
const meta = metaSnap.data() as ApiWheelMeta
if (meta.uid !== uid) {
return null
}
const newWheelMeta: Partial<ApiWheelMeta> = {
updated: Date.now()
}
if (wheel.config && wheel.config.title !== wheelMeta.title) {
newWheelMeta.title = wheel.config.title
const newMeta: Partial<ApiWheelMeta> = { updated: new Date() }
if (wheel.config && wheel.config.title !== meta.title) {
newMeta.title = wheel.config.title
}
if (visibility) {
newWheelMeta.visibility = visibility
newMeta.visibility = visibility
}
await wheelMetaDoc.update(newWheelMeta)
await metaDoc.update(newMeta)
const wheelDoc = db.doc(`wheels/${path}`)
await wheelDoc.update({ ...wheel } satisfies Partial<ApiWheel>)
return wheelMeta.path
return meta.path
}

const getNewWheelPath = async () => {
let path: string
let snap: FirebaseFirestore.DocumentSnapshot<FirebaseFirestore.DocumentData>
let snap: FirebaseFirestore.DocumentSnapshot
do {
path = getRandomPath()
snap = await db.doc(`wheel-meta/${path}`).get()
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export interface ApiWheelMeta {
path: string
uid: string
visibility: WheelVisibility
created: number
updated: number | null
created: Date
updated: Date | null
title: string
views: number
}
Expand Down

0 comments on commit e00cf73

Please sign in to comment.