File size: 694 Bytes
82fcab7
 
 
 
 
 
da7f5d6
82fcab7
 
da7f5d6
82fcab7
 
 
 
 
 
 
 
 
 
da7f5d6
82fcab7
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { collections } from "$lib/server/database.js";
import { z } from "zod";

export async function PATCH({ locals, request }) {
	const json = await request.json();

	const { ethicsModalAccepted, ...settings } = z
		.object({
			shareConversationsWithModelAuthors: z.boolean().default(true),
			ethicsModalAccepted: z.boolean().optional(),
		})
		.parse(json);

	await collections.settings.updateOne(
		{
			sessionId: locals.sessionId,
		},
		{
			$set: {
				...settings,
				...(ethicsModalAccepted && { ethicsModalAcceptedAt: new Date() }),
				updatedAt: new Date(),
			},
			$setOnInsert: {
				createdAt: new Date(),
			},
		},
		{
			upsert: true,
		}
	);

	return new Response();
}