@@ -12,7 +12,7 @@ import {
1212 searchUserByUinRequest ,
1313 searchUserByUinResponse ,
1414} from "common/types/user.js" ;
15- import { getUinHash } from "api/functions/uin.js" ;
15+ import { getUinHash , getUserIdByUin } from "api/functions/uin.js" ;
1616import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi" ;
1717import { QueryCommand } from "@aws-sdk/client-dynamodb" ;
1818import { genericConfig } from "common/config.js" ;
@@ -30,11 +30,7 @@ const userRoute: FastifyPluginAsync = async (fastify, _options) => {
3030 "/findUserByUin" ,
3131 {
3232 schema : withRoles (
33- [
34- AppRoles . VIEW_USER_INFO ,
35- AppRoles . TICKETS_MANAGER ,
36- AppRoles . TICKETS_SCANNER ,
37- ] ,
33+ [ AppRoles . VIEW_USER_INFO ] ,
3834 withTags ( [ "Generic" ] , {
3935 summary : "Find a user by UIN." ,
4036 body : searchUserByUinRequest ,
@@ -53,40 +49,13 @@ const userRoute: FastifyPluginAsync = async (fastify, _options) => {
5349 onRequest : fastify . authorizeFromSchema ,
5450 } ,
5551 async ( request , reply ) => {
56- const uinHash = await getUinHash ( {
57- pepper : fastify . secretConfig . UIN_HASHING_SECRET_PEPPER ,
58- uin : request . body . uin ,
59- } ) ;
60- const queryCommand = new QueryCommand ( {
61- TableName : genericConfig . UserInfoTable ,
62- IndexName : "UinHashIndex" ,
63- KeyConditionExpression : "uinHash = :hash" ,
64- ExpressionAttributeValues : {
65- ":hash" : { S : uinHash } ,
66- } ,
67- } ) ;
68- const response = await fastify . dynamoClient . send ( queryCommand ) ;
69- if ( ! response || ! response . Items ) {
70- throw new DatabaseFetchError ( {
71- message : "Failed to retrieve user from database." ,
72- } ) ;
73- }
74- if ( response . Items . length === 0 ) {
75- throw new ValidationError ( {
76- message :
77- "Failed to find user in database. Please have the user run sync and try again." ,
78- } ) ;
79- }
80- if ( response . Items . length > 1 ) {
81- throw new ValidationError ( {
82- message :
83- "Multiple users tied to this UIN. This user probably had a NetID change. Please contact support." ,
84- } ) ;
85- }
86- const data = unmarshall ( response . Items [ 0 ] ) as { id : string } ;
87- return reply . send ( {
88- email : data . id ,
89- } ) ;
52+ return reply . send (
53+ await getUserIdByUin ( {
54+ dynamoClient : fastify . dynamoClient ,
55+ uin : request . body . uin ,
56+ pepper : fastify . secretConfig . UIN_HASHING_SECRET_PEPPER ,
57+ } ) ,
58+ ) ;
9059 } ,
9160 ) ;
9261} ;
0 commit comments