Tanya b6a9765315
Some checks failed
CI / skip-ci-check (push) Successful in 1m27s
CI / skip-ci-check (pull_request) Successful in 1m27s
CI / lint-and-type-check (pull_request) Has been cancelled
CI / python-lint (pull_request) Has been cancelled
CI / test-backend (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / secret-scanning (pull_request) Has been cancelled
CI / dependency-scan (pull_request) Has been cancelled
CI / sast-scan (pull_request) Has been cancelled
CI / workflow-summary (pull_request) Has been cancelled
CI / lint-and-type-check (push) Successful in 2m4s
CI / python-lint (push) Successful in 1m53s
CI / test-backend (push) Successful in 2m37s
CI / build (push) Failing after 2m13s
CI / secret-scanning (push) Successful in 1m40s
CI / dependency-scan (push) Successful in 1m34s
CI / sast-scan (push) Successful in 2m42s
CI / workflow-summary (push) Successful in 1m26s
chore: Update project configuration and enhance code quality
This commit modifies the `.gitignore` file to exclude Python library directories while ensuring the viewer-frontend's `lib` directory is not ignored. It also updates the `package.json` to activate the virtual environment during backend tests, improving the testing process. Additionally, the CI workflow is enhanced to prevent duplicate runs for branches with open pull requests. Various components in the viewer frontend are updated to ensure consistent naming conventions and improve type safety. These changes contribute to a cleaner codebase and a more efficient development workflow.
2026-01-07 12:29:17 -05:00

116 lines
2.0 KiB
TypeScript

import { prisma } from './db';
export interface SearchFilters {
people?: number[];
tags?: number[];
dateFrom?: Date;
dateTo?: Date;
mediaType?: 'all' | 'photos' | 'videos';
page?: number;
pageSize?: number;
}
export async function searchPhotos(filters: SearchFilters) {
const {
people = [],
tags = [],
dateFrom,
dateTo,
mediaType = 'all',
page = 1,
pageSize = 30,
} = filters;
const skip = (page - 1) * pageSize;
// Build where clause
const where: any = {
processed: true,
};
// Media type filter
if (mediaType !== 'all') {
if (mediaType === 'photos') {
where.media_type = 'image';
} else if (mediaType === 'videos') {
where.media_type = 'video';
}
}
// Date filter
if (dateFrom || dateTo) {
where.date_taken = {};
if (dateFrom) {
where.date_taken.gte = dateFrom;
}
if (dateTo) {
where.date_taken.lte = dateTo;
}
}
// People filter (photo has face with person_id in list)
if (people.length > 0) {
where.faces = {
some: {
personId: { in: people },
},
};
}
// Tags filter
if (tags.length > 0) {
where.PhotoTagLinkage = {
some: {
tagId: { in: tags },
},
};
}
// Execute query
const [photos, total] = await Promise.all([
prisma.photo.findMany({
where,
include: {
Face: {
include: {
Person: true,
},
},
PhotoTagLinkage: {
include: {
Tag: true,
},
},
},
orderBy: { date_taken: 'desc' },
skip,
take: pageSize,
}),
prisma.photo.count({ where }),
]);
return {
photos,
total,
page,
pageSize,
totalPages: Math.ceil(total / pageSize),
};
}
export async function getAllPeople() {
return prisma.person.findMany({
orderBy: [
{ first_name: 'asc' },
{ last_name: 'asc' },
],
});
}
export async function getAllTags() {
return prisma.tag.findMany({
orderBy: { tag_name: 'asc' },
});
}