14 Commits
1.1.4 ... 1.1.6

Author SHA1 Message Date
William Oldham
f4e9a96666 Merge pull request #24 from movie-web/dev
Update bugfix
2023-12-14 20:48:14 +00:00
William Oldham
60dda8ac57 Merge branch 'master' into dev 2023-12-14 20:48:04 +00:00
William Oldham
d84cdc4239 Merge pull request #23 from movie-web/fix-show-delete
Fix show deletion
2023-12-14 20:47:40 +00:00
mrjvs
c2cba27e68 remove unused import 2023-12-14 21:10:48 +01:00
mrjvs
c3259156ac bump version 2023-12-14 21:07:38 +01:00
mrjvs
9ef12d1c0f Delete all entries of a show 2023-12-14 21:07:24 +01:00
William Oldham
e173003f55 Merge pull request #22 from movie-web/dev
v1.1.5 - Progress importing now uses the user's date
2023-12-06 20:03:22 +00:00
William Oldham
9f90ba7da2 Merge pull request #21 from movie-web/progress-date
Add UpdatedAt from User date for Progress
2023-12-06 20:01:35 +00:00
William Oldham
05bf651939 Revert "Use date to compare progress items"
This reverts commit cf0125755c.
2023-12-06 19:59:50 +00:00
William Oldham
cf0125755c Use date to compare progress items 2023-12-06 19:55:09 +00:00
William Oldham
4129b80828 Use movie-web birthday 2023-12-06 19:49:30 +00:00
William Oldham
e5c3cde51b Only use user date on bulk import 2023-12-06 19:46:22 +00:00
William Oldham
4bf0285d06 Bump version 2023-12-06 19:43:57 +00:00
William Oldham
53d5ca1461 Add updatedAt saving into progress imports 2023-12-06 19:43:37 +00:00
3 changed files with 30 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "1.1.4",
"version": "1.1.6",
"private": true,
"homepage": "https://github.com/movie-web/backend",
"engines": {

View File

@@ -6,7 +6,6 @@ import {
import { StatusError } from '@/services/error';
import { handle } from '@/services/handler';
import { makeRouter } from '@/services/router';
import { randomUUID } from 'crypto';
import { z } from 'zod';
const bookmarkDataSchema = z.object({

View File

@@ -6,6 +6,7 @@ import {
import { StatusError } from '@/services/error';
import { handle } from '@/services/handler';
import { makeRouter } from '@/services/router';
import { FilterQuery } from '@mikro-orm/core';
import { randomUUID } from 'crypto';
import { z } from 'zod';
@@ -18,6 +19,7 @@ const progressItemSchema = z.object({
episodeId: z.string().optional(),
seasonNumber: z.number().optional(),
episodeNumber: z.number().optional(),
updatedAt: z.string().datetime({ offset: true }).optional(),
});
export const userProgressRouter = makeRouter((app) => {
@@ -100,7 +102,9 @@ export const userProgressRouter = makeRouter((app) => {
if (newItemIndex > -1) {
const newItem = newItems[newItemIndex];
if (existingItem.watched < newItem.watched) {
existingItem.updatedAt = new Date();
existingItem.updatedAt = defaultAndCoerceDateTime(
newItem.updatedAt,
);
existingItem.watched = newItem.watched;
}
itemsUpserted.push(existingItem);
@@ -123,7 +127,7 @@ export const userProgressRouter = makeRouter((app) => {
tmdbId: newItem.tmdbId,
userId: params.uid,
watched: newItem.watched,
updatedAt: new Date(),
updatedAt: defaultAndCoerceDateTime(newItem.updatedAt),
});
}
@@ -161,22 +165,28 @@ export const userProgressRouter = makeRouter((app) => {
if (auth.user.id !== params.uid)
throw new StatusError('Cannot modify user other than yourself', 403);
const progressItem = await em.findOne(ProgressItem, {
const query: FilterQuery<ProgressItem> = {
userId: params.uid,
tmdbId: params.tmdbid,
episodeId: body.episodeId,
seasonId: body.seasonId,
});
if (!progressItem) {
};
if (body.seasonId) query.seasonId = body.seasonId;
if (body.episodeId) query.episodeId = body.episodeId;
const progressItems = await em.find(ProgressItem, query);
if (progressItems.length === 0) {
return {
count: 0,
tmdbId: params.tmdbid,
episodeId: body.episodeId,
seasonId: body.seasonId,
};
}
await em.removeAndFlush(progressItem);
progressItems.forEach((v) => em.remove(v));
await em.flush();
return {
count: progressItems.length,
tmdbId: params.tmdbid,
episodeId: body.episodeId,
seasonId: body.seasonId,
@@ -207,3 +217,14 @@ export const userProgressRouter = makeRouter((app) => {
}),
);
});
// 13th July 2021 - movie-web epoch
const minEpoch = 1626134400000;
function defaultAndCoerceDateTime(dateTime: string | undefined) {
const epoch = dateTime ? new Date(dateTime).getTime() : Date.now();
const clampedEpoch = Math.max(minEpoch, Math.min(epoch, Date.now()));
return new Date(clampedEpoch);
}