mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-12-08 04:09:07 +00:00
feat(server): add updatedAt to Asset, Album and User (#1566)
* feat: add updatedAt info to DTO and generate api * chore: remove unsued file * chore: Add update statement to add/remove asset/user to album * fix: test
This commit is contained in:
@@ -213,18 +213,27 @@ export class AlbumRepository implements IAlbumRepository {
|
||||
}
|
||||
|
||||
async get(albumId: string): Promise<AlbumEntity | undefined> {
|
||||
const query = this.albumRepository.createQueryBuilder('album');
|
||||
|
||||
const album = await query
|
||||
.where('album.id = :albumId', { albumId })
|
||||
.leftJoinAndSelect('album.sharedUsers', 'sharedUser')
|
||||
.leftJoinAndSelect('sharedUser.userInfo', 'userInfo')
|
||||
.leftJoinAndSelect('album.assets', 'assets')
|
||||
.leftJoinAndSelect('assets.assetInfo', 'assetInfo')
|
||||
.leftJoinAndSelect('assetInfo.exifInfo', 'exifInfo')
|
||||
.leftJoinAndSelect('album.sharedLinks', 'sharedLinks')
|
||||
.orderBy('"assetInfo"."createdAt"::timestamptz', 'ASC')
|
||||
.getOne();
|
||||
const album = await this.albumRepository.findOne({
|
||||
where: { id: albumId },
|
||||
relations: {
|
||||
sharedUsers: {
|
||||
userInfo: true,
|
||||
},
|
||||
assets: {
|
||||
assetInfo: {
|
||||
exifInfo: true,
|
||||
},
|
||||
},
|
||||
sharedLinks: true,
|
||||
},
|
||||
order: {
|
||||
assets: {
|
||||
assetInfo: {
|
||||
createdAt: 'ASC',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!album) {
|
||||
return;
|
||||
@@ -249,11 +258,14 @@ export class AlbumRepository implements IAlbumRepository {
|
||||
}
|
||||
|
||||
await this.userAlbumRepository.save([...newRecords]);
|
||||
await this.albumRepository.update({ id: album.id }, { updatedAt: new Date().toISOString() });
|
||||
|
||||
return this.get(album.id) as Promise<AlbumEntity>; // There is an album for sure
|
||||
}
|
||||
|
||||
async removeUser(album: AlbumEntity, userId: string): Promise<void> {
|
||||
await this.userAlbumRepository.delete({ albumId: album.id, sharedUserId: userId });
|
||||
await this.albumRepository.update({ id: album.id }, { updatedAt: new Date().toISOString() });
|
||||
}
|
||||
|
||||
async removeAssets(album: AlbumEntity, removeAssetsDto: RemoveAssetsDto): Promise<number> {
|
||||
@@ -262,6 +274,8 @@ export class AlbumRepository implements IAlbumRepository {
|
||||
assetId: In(removeAssetsDto.assetIds),
|
||||
});
|
||||
|
||||
await this.albumRepository.update({ id: album.id }, { updatedAt: new Date().toISOString() });
|
||||
|
||||
return res.affected || 0;
|
||||
}
|
||||
|
||||
@@ -290,6 +304,8 @@ export class AlbumRepository implements IAlbumRepository {
|
||||
|
||||
await this.assetAlbumRepository.save([...newRecords]);
|
||||
|
||||
await this.albumRepository.update({ id: album.id }, { updatedAt: new Date().toISOString() });
|
||||
|
||||
return {
|
||||
successfullyAdded: newRecords.length,
|
||||
alreadyInAlbum: alreadyExisting,
|
||||
|
||||
@@ -32,6 +32,7 @@ describe('Album service', () => {
|
||||
albumEntity.id = albumId;
|
||||
albumEntity.albumName = 'name';
|
||||
albumEntity.createdAt = 'date';
|
||||
albumEntity.updatedAt = 'date';
|
||||
albumEntity.sharedUsers = [];
|
||||
albumEntity.assets = [];
|
||||
albumEntity.albumThumbnailAssetId = null;
|
||||
@@ -183,6 +184,7 @@ describe('Album service', () => {
|
||||
albumName: 'name',
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: 'date',
|
||||
updatedAt: 'date',
|
||||
id: 'f19ab956-4761-41ea-a5d6-bae948308d58',
|
||||
ownerId,
|
||||
shared: false,
|
||||
|
||||
@@ -27,6 +27,7 @@ export class AssetCore {
|
||||
|
||||
createdAt: timeUtils.checkValidTimestamp(dto.createdAt) ? dto.createdAt : new Date().toISOString(),
|
||||
modifiedAt: timeUtils.checkValidTimestamp(dto.modifiedAt) ? dto.modifiedAt : new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
|
||||
deviceAssetId: dto.deviceAssetId,
|
||||
deviceId: dto.deviceId,
|
||||
|
||||
@@ -23,6 +23,7 @@ describe('TagService', () => {
|
||||
shouldChangePassword: true,
|
||||
createdAt: '2022-12-02T19:29:23.603Z',
|
||||
deletedAt: undefined,
|
||||
updatedAt: '2022-12-02T19:29:23.603Z',
|
||||
tags: [],
|
||||
oauthId: 'oauth-id-1',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user