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:
Alex
2023-02-06 10:24:58 -06:00
committed by GitHub
parent b8d2f5b373
commit 29bb1f7ef2
25 changed files with 190 additions and 75 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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',
});