feat(api): set person color (#15937)

This commit is contained in:
Jason Rasmussen
2025-02-07 10:06:58 -05:00
committed by GitHub
parent 2e5007adef
commit 23014c263b
18 changed files with 182 additions and 21 deletions

View File

@@ -355,7 +355,7 @@ describe(PersonService.name, () => {
sut.reassignFaces(authStub.admin, personStub.noName.id, {
data: [{ personId: personStub.withName.id, assetId: assetStub.image.id }],
}),
).resolves.toEqual([personStub.noName]);
).resolves.toBeDefined();
expect(jobMock.queueAll).toHaveBeenCalledWith([
{
@@ -448,7 +448,7 @@ describe(PersonService.name, () => {
it('should create a new person', async () => {
personMock.create.mockResolvedValue(personStub.primaryPerson);
await expect(sut.create(authStub.admin, {})).resolves.toBe(personStub.primaryPerson);
await expect(sut.create(authStub.admin, {})).resolves.toBeDefined();
expect(personMock.create).toHaveBeenCalledWith({ ownerId: authStub.admin.user.id });
});

View File

@@ -104,7 +104,7 @@ export class PersonService extends BaseService {
await this.personRepository.reassignFace(face.id, personId);
}
result.push(person);
result.push(mapPerson(person));
}
if (changeFeaturePhoto.length > 0) {
// Remove duplicates
@@ -178,20 +178,23 @@ export class PersonService extends BaseService {
});
}
create(auth: AuthDto, dto: PersonCreateDto): Promise<PersonResponseDto> {
return this.personRepository.create({
async create(auth: AuthDto, dto: PersonCreateDto): Promise<PersonResponseDto> {
const person = await this.personRepository.create({
ownerId: auth.user.id,
name: dto.name,
birthDate: dto.birthDate,
isHidden: dto.isHidden,
isFavorite: dto.isFavorite,
color: dto.color,
});
return mapPerson(person);
}
async update(auth: AuthDto, id: string, dto: PersonUpdateDto): Promise<PersonResponseDto> {
await this.requireAccess({ auth, permission: Permission.PERSON_UPDATE, ids: [id] });
const { name, birthDate, isHidden, featureFaceAssetId: assetId, isFavorite } = dto;
const { name, birthDate, isHidden, featureFaceAssetId: assetId, isFavorite, color } = dto;
// TODO: set by faceId directly
let faceId: string | undefined = undefined;
if (assetId) {
@@ -211,6 +214,7 @@ export class PersonService extends BaseService {
birthDate,
isHidden,
isFavorite,
color,
});
if (assetId) {

View File

@@ -31,6 +31,8 @@ describe(SearchService.name, () => {
it('should pass options to search', async () => {
const { name } = personStub.withName;
personMock.getByName.mockResolvedValue([]);
await sut.searchPerson(authStub.user1, { name, withHidden: false });
expect(personMock.getByName).toHaveBeenCalledWith(authStub.user1.user.id, name, { withHidden: false });

View File

@@ -1,8 +1,9 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { AssetMapOptions, AssetResponseDto, mapAsset } from 'src/dtos/asset-response.dto';
import { AuthDto } from 'src/dtos/auth.dto';
import { PersonResponseDto } from 'src/dtos/person.dto';
import { mapPerson, PersonResponseDto } from 'src/dtos/person.dto';
import {
mapPlaces,
MetadataSearchDto,
PlacesResponseDto,
RandomSearchDto,
@@ -12,7 +13,6 @@ import {
SearchSuggestionRequestDto,
SearchSuggestionType,
SmartSearchDto,
mapPlaces,
} from 'src/dtos/search.dto';
import { AssetEntity } from 'src/entities/asset.entity';
import { AssetOrder } from 'src/enum';
@@ -24,7 +24,8 @@ import { isSmartSearchEnabled } from 'src/utils/misc';
@Injectable()
export class SearchService extends BaseService {
async searchPerson(auth: AuthDto, dto: SearchPeopleDto): Promise<PersonResponseDto[]> {
return this.personRepository.getByName(auth.user.id, dto.name, { withHidden: dto.withHidden });
const people = await this.personRepository.getByName(auth.user.id, dto.name, { withHidden: dto.withHidden });
return people.map((person) => mapPerson(person));
}
async searchPlaces(dto: SearchPlacesDto): Promise<PlacesResponseDto[]> {