Skip to content

Instantly share code, notes, and snippets.

@PhantomKnight287
Created September 30, 2024 09:34
Show Gist options
  • Select an option

  • Save PhantomKnight287/9e5351fbd2e10634659f70f666a4e36e to your computer and use it in GitHub Desktop.

Select an option

Save PhantomKnight287/9e5351fbd2e10634659f70f666a4e36e to your computer and use it in GitHub Desktop.
import {randomBytes} from "crypto"
async createChat(userId: string, body: CreateChatDTO) {
const key = randomBytes(32).toString('base64');
const iv = randomBytes(16).toString('base64');
const chat = await prisma.chat.create({
data: {
id: `ch_${createId()}`,
name: body.name,
topic: body.topic,
members: {
create: {
id: `cm_${createId()}`,
role: 'Owner',
userId,
},
},
},
});
return {
...chat,
key: key,
iv: iv,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment