-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from swisstopo/feature/assets-253-verweise-in…
…-gleicher-workgroup Feature/assets 253 verweise in gleicher workgroup
- Loading branch information
Showing
14 changed files
with
121 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/server-asset-sg/src/features/asset-edit/asset-edit.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; | ||
import * as O from 'fp-ts/Option'; | ||
|
||
import { AssetEditData } from './asset-edit.repo'; | ||
import { PrismaService } from '@/core/prisma.service'; | ||
|
||
@Injectable() | ||
export class AssetEditService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
public async validateReferencesOrThrow(data: AssetEditData, id?: number): Promise<void> { | ||
// check if any of the siblings are in another workgroup | ||
for (const assetYId of data.patch.siblingAssetIds) { | ||
const siblingCandidate = await this.prismaService.asset.findUnique({ | ||
where: { assetId: assetYId }, | ||
select: { workgroupId: true }, | ||
}); | ||
if (siblingCandidate?.workgroupId !== data.patch.workgroupId) { | ||
throw new HttpException( | ||
'Sibling assets must be in the same workgroup as the edited asset', | ||
HttpStatus.UNPROCESSABLE_ENTITY | ||
); | ||
} | ||
} | ||
|
||
// check if the parent asset is in another workgroup | ||
const assetMainId = O.toUndefined(data.patch.assetMainId); | ||
if (assetMainId) { | ||
const assetMain = await this.prismaService.asset.findUnique({ | ||
where: { assetId: assetMainId }, | ||
select: { workgroupId: true }, | ||
}); | ||
if (assetMain?.workgroupId !== data.patch.workgroupId) { | ||
throw new HttpException('Cannot assign parent asset from different workgroup', HttpStatus.UNPROCESSABLE_ENTITY); | ||
} | ||
} | ||
|
||
// check if any of the subordinate assets are in another workgroup for exisiting assets | ||
if (id) { | ||
const childAssets = await this.prismaService.asset.findMany({ | ||
where: { assetMainId: id }, | ||
select: { workgroupId: true }, | ||
}); | ||
|
||
for (const child of childAssets) { | ||
if (child.workgroupId !== data.patch.workgroupId) { | ||
throw new HttpException( | ||
'Child assets must be in the same workgroup as the parent asset', | ||
HttpStatus.UNPROCESSABLE_ENTITY | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters