File size: 681 Bytes
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 { subMinutes } from "date-fns";
import { z } from "zod";

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

	const settings = z
		.object({
			shareConversationsWithModelAuthors: z.boolean().default(true),
			ethicsModalAcceptedAt: z.optional(z.date({ coerce: true }).min(subMinutes(new Date(), 5))),
		})
		.parse(json);

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

	return new Response();
}