Skip to content

Commit

Permalink
feat(signature-collection-api): Expose canSign/info
Browse files Browse the repository at this point in the history
  • Loading branch information
kksteini committed Sep 18, 2024
1 parent e994855 commit 2640d80
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IsString } from 'class-validator'
import { Field, InputType } from '@nestjs/graphql'

@InputType()
export class SignatureCollectionCanSignInput {
@Field()
@IsString()
signeeNationalId!: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ReasonKey } from '@island.is/clients/signature-collection'
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql'

registerEnumType(ReasonKey, { name: 'ReasonKey' })
@ObjectType()
export class CanSignInfo {
@Field(() => [ReasonKey])
reasons?: ReasonKey[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CurrentSignee } from './decorators/signee.decorator'
import { ApiScope } from '@island.is/auth/scopes'
import { SignatureCollectionCancelListsInput } from './dto/cencelLists.input'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionCanSignInput } from './dto/canSign.input'
@UseGuards(IdsUserGuard, ScopesGuard, UserAccessGuard)
@Resolver()
@Audit({ namespace: '@island.is/api/signature-collection' })
Expand Down Expand Up @@ -125,6 +126,19 @@ export class SignatureCollectionResolver {
return signee
}

@Scopes(ApiScope.signatureCollection)
@Query(() => Boolean)
@AccessRequirement(OwnerAccess.AllowActor)
@Audit()
async signatureCollectionCanSign(
@Args('input') input: SignatureCollectionCanSignInput,
@CurrentUser() user: User,
): Promise<boolean> {
return (
await this.signatureCollectionService.signee(user, input.signeeNationalId)
).canSign
}

@Scopes(ApiScope.signatureCollection)
@AccessRequirement(UserAccess.RestrictActor)
@Mutation(() => SignatureCollectionSuccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import { SignatureCollectionNationalIdInput } from './dto/nationalId.input'
import { SignatureCollectionSignatureIdInput } from './dto/signatureId.input'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input'
import { SignatureCollectionCanSignInput } from './dto/canSign.input'
import { ReasonKey } from '@island.is/clients/signature-collection'
import { CanSignInfo } from './models/canSignInfo.model'

@UseGuards(IdsUserGuard, ScopesGuard)
@Scopes(AdminPortalScope.signatureCollectionProcess)
Expand All @@ -42,6 +45,26 @@ export class SignatureCollectionAdminResolver {
private signatureCollectionManagerService: SignatureCollectionManagerService,
) {}

@Query(() => CanSignInfo, { nullable: true })
@Scopes(
AdminPortalScope.signatureCollectionManage,
AdminPortalScope.signatureCollectionProcess,
)
async signatureCollectionAdminCanSignInfo(
@CurrentUser()
user: User,
@Args('input') input: SignatureCollectionCanSignInput,
): Promise<CanSignInfo> {
const canSignInfo = await this.signatureCollectionService.getCanSignInfo(
user,
input.signeeNationalId,
)

return {
reasons: canSignInfo,
}
}

@Query(() => SignatureCollection)
@Scopes(
AdminPortalScope.signatureCollectionManage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
import { SignatureCollectionBulk } from './models/bulk.model'
import { SignatureCollectionCandidateLookUp } from './models/signee.model'
import { SignatureCollectionListInput } from './dto/singatureList.input'
import { SignatureCollectionAdminClientService } from '@island.is/clients/signature-collection'
import {
ReasonKey,
SignatureCollectionAdminClientService,
SignatureCollectionClientService,
} from '@island.is/clients/signature-collection'
import { SignatureCollectionExtendDeadlineInput } from './dto/extendDeadline.input'
import { User } from '@island.is/auth-nest-tools'
import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input'
Expand All @@ -22,6 +26,7 @@ import { SignatureCollectionIdInput } from './dto/collectionId.input'
export class SignatureCollectionAdminService {
constructor(
private signatureCollectionClientService: SignatureCollectionAdminClientService,
private signatureCollectionBasicService: SignatureCollectionClientService,
) {}

async currentCollection(user: User): Promise<SignatureCollection> {
Expand All @@ -39,6 +44,15 @@ export class SignatureCollectionAdminService {
return await this.signatureCollectionClientService.getList(listId, user)
}

async getCanSignInfo(
auth: User,
nationalId: string,
): Promise<ReasonKey[] | undefined> {
return (
await this.signatureCollectionBasicService.getSignee(auth, nationalId)
).canSignInfo
}

async signatures(
listId: string,
user: User,
Expand Down

0 comments on commit 2640d80

Please sign in to comment.