Timo Martinson
Timo Martinson
Explore posts from servers
DDeno
Created by Timo Martinson on 3/3/2024 in #help
How to start using data validation in kv?
Hey fellows! I want to dive into data validation. Any experience or suggestions? Feel free to post a commented version of the repository I provided here:
import Post from '@/modules/post/model.ts'

import { setData, getData, listData, removeData } from '@/helpers/data.ts'

type PostParams = {
blogSlug?: string
postSlug?: string
postInput?: Post
}

class PostRepository {
static async createPost({ postInput, blogSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postInput?.slug as string]
const result = await setData({ key, value: postInput })
if (result.ok) return await getData({ key })
}

static async listPosts({ blogSlug }: PostParams) {
const prefix = ['blog', blogSlug as string, 'post']
return await listData({ prefix })
}

static async showPost({ blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
return await getData({ key })
}

static async updatePost({ postInput, blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
return await setData({ key, value: postInput })
}

static async deletePost({ blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
await removeData({ key })
}
}

export default PostRepository
import Post from '@/modules/post/model.ts'

import { setData, getData, listData, removeData } from '@/helpers/data.ts'

type PostParams = {
blogSlug?: string
postSlug?: string
postInput?: Post
}

class PostRepository {
static async createPost({ postInput, blogSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postInput?.slug as string]
const result = await setData({ key, value: postInput })
if (result.ok) return await getData({ key })
}

static async listPosts({ blogSlug }: PostParams) {
const prefix = ['blog', blogSlug as string, 'post']
return await listData({ prefix })
}

static async showPost({ blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
return await getData({ key })
}

static async updatePost({ postInput, blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
return await setData({ key, value: postInput })
}

static async deletePost({ blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
await removeData({ key })
}
}

export default PostRepository
Thank you!
6 replies
DDeno
Created by Timo Martinson on 8/21/2023 in #help
Property 'params' does not exist on type 'Context<State, Record<string, any>> ... what to do?
I want to access params in oak, but typescript complains. What can I do about that? Thanks.
3 replies
DDeno
Created by Timo Martinson on 8/1/2023 in #help
How to access request body in Deno?
Thank you.
2 replies
DDeno
Created by Timo Martinson on 7/22/2023 in #help
Where to store this key — and how?
const cryptoKey =
await crypto.subtle.generateKey({
name: 'HMAC', hash: 'SHA-512'
}, true, ['sign', 'verify'])
const cryptoKey =
await crypto.subtle.generateKey({
name: 'HMAC', hash: 'SHA-512'
}, true, ['sign', 'verify'])
5 replies
DDeno
Created by Timo Martinson on 7/22/2023 in #help
Typing DateTimes
interface ICity {
slug: string
name: string
description?: string
createdAt: Date
updatedAt: Date
}
interface ICity {
slug: string
name: string
description?: string
createdAt: Date
updatedAt: Date
}
can I save strings like "2023-09-10 18:16:00" as createdAt and updatedAt ?
7 replies
DDeno
Created by Timo Martinson on 7/20/2023 in #help
KV: What to return from here?
// Create City
router.post('/cities', async (context) => {
const data = await context.request.body().value
if (data.slug && data.name) {
await kv.set(['cities', data.slug], {
slug: data.slug,
name: data.name,
description: data.description
} satisfies ICity)
}
})
// Create City
router.post('/cities', async (context) => {
const data = await context.request.body().value
if (data.slug && data.name) {
await kv.set(['cities', data.slug], {
slug: data.slug,
name: data.name,
description: data.description
} satisfies ICity)
}
})
24 replies
DDeno
Created by Timo Martinson on 7/4/2023 in #help
Absolute Imports with Oak
I would like to have absolute imports in my Oak-API ... 😉
5 replies
DDeno
Created by Timo Martinson on 6/11/2023 in #help
Uncaught (in promise) TypeError: cannot read headers: request closed
What is this? How to fix it?
34 replies
DDeno
Created by Timo Martinson on 5/4/2023 in #help
How to monetize an app?
I would like to monetize my apps in a certain way. Mabye limit some features. How to approach monetization?
2 replies
DDeno
Created by Timo Martinson on 4/28/2023 in #help
absolute imports in fresh?
how do you get this accomplished?
4 replies