mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 16:33:26 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
783d89492d | ||
|
4663b2c1f7 | ||
|
ceea274e70 | ||
|
6d2dcd04e9 | ||
|
8a3c0d6edb | ||
|
72657e73c8 | ||
|
1bb344ec2f | ||
|
b30623c483 | ||
|
233cb11ac6 | ||
|
d3aa4847f8 | ||
|
4bf2e658f7 |
@@ -13,7 +13,7 @@ module.exports = {
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint'],
|
||||
ignorePatterns: ['./src/db/migrations/**/*'],
|
||||
ignorePatterns: ['src/db/migrations/**/*'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.3",
|
||||
"private": true,
|
||||
"homepage": "https://github.com/movie-web/backend",
|
||||
"engines": {
|
||||
|
@@ -587,12 +587,12 @@
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "uuid"
|
||||
"mappedType": "text"
|
||||
},
|
||||
"application_theme": {
|
||||
"name": "application_theme",
|
||||
|
14
src/db/migrations/Migration20231122231620.ts
Normal file
14
src/db/migrations/Migration20231122231620.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20231122231620 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('alter table "user_settings" alter column "id" type text using ("id"::text);');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('alter table "user_settings" alter column "id" drop default;');
|
||||
this.addSql('alter table "user_settings" alter column "id" type uuid using ("id"::text::uuid);');
|
||||
}
|
||||
|
||||
}
|
@@ -1,10 +1,9 @@
|
||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
@Entity({ tableName: 'user_settings' })
|
||||
export class UserSettings {
|
||||
@PrimaryKey({ name: 'id', type: 'uuid' })
|
||||
id: string = randomUUID();
|
||||
@PrimaryKey({ name: 'id', type: 'text' })
|
||||
id!: string;
|
||||
|
||||
@Property({ name: 'application_theme', nullable: true })
|
||||
applicationTheme?: string | null;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Session } from '@/db/models/Session';
|
||||
import { Session, formatSession } from '@/db/models/Session';
|
||||
import { StatusError } from '@/services/error';
|
||||
import { handle } from '@/services/handler';
|
||||
import { makeRouter } from '@/services/router';
|
||||
@@ -32,4 +32,32 @@ export const sessionRouter = makeRouter((app) => {
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
app.patch(
|
||||
'/sessions/:sid',
|
||||
{
|
||||
schema: {
|
||||
params: z.object({
|
||||
sid: z.string(),
|
||||
}),
|
||||
body: z.object({
|
||||
deviceName: z.string().min(1).optional(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
handle(async ({ auth, params, body, em }) => {
|
||||
await auth.assert();
|
||||
|
||||
const targetedSession = await em.findOne(Session, { id: params.sid });
|
||||
if (!targetedSession) throw new StatusError('Not found', 404);
|
||||
if (targetedSession.id !== params.sid)
|
||||
throw new StatusError('Cannot edit sessions other than your own', 401);
|
||||
|
||||
if (body.deviceName) targetedSession.device = body.deviceName;
|
||||
|
||||
await em.persistAndFlush(targetedSession);
|
||||
|
||||
return formatSession(targetedSession);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
@@ -38,9 +38,9 @@ export const userSettingsRouter = makeRouter((app) => {
|
||||
uid: z.string(),
|
||||
}),
|
||||
body: z.object({
|
||||
applicationLanguage: z.string().optional(),
|
||||
applicationTheme: z.string().optional(),
|
||||
defaultSubtitleLanguage: z.string().optional(),
|
||||
applicationLanguage: z.string().nullable().optional(),
|
||||
applicationTheme: z.string().nullable().optional(),
|
||||
defaultSubtitleLanguage: z.string().nullable().optional(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
@@ -58,12 +58,12 @@ export const userSettingsRouter = makeRouter((app) => {
|
||||
settings.id = params.uid;
|
||||
}
|
||||
|
||||
if (body.applicationLanguage)
|
||||
if (body.applicationLanguage !== undefined)
|
||||
settings.applicationLanguage = body.applicationLanguage;
|
||||
if (body.applicationTheme)
|
||||
settings.applicationTheme = body.applicationTheme;
|
||||
if (body.defaultSubtitleLanguage)
|
||||
if (body.defaultSubtitleLanguage !== undefined)
|
||||
settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage;
|
||||
if (body.applicationTheme !== undefined)
|
||||
settings.applicationTheme = body.applicationTheme;
|
||||
|
||||
await em.persistAndFlush(settings);
|
||||
return formatUserSettings(settings);
|
||||
|
Reference in New Issue
Block a user