@@ -676,43 +676,53 @@ export class DbService {
676676 }
677677
678678 /**
679- * Gets the public key for a given eName.
679+ * Gets all public keys for a given eName.
680680 * @param eName - The eName identifier
681- * @returns The public key string , or null if not found
681+ * @returns Array of public key strings , or empty array if not found
682682 */
683- async getPublicKey ( eName : string ) : Promise < string | null > {
683+ async getPublicKeys ( eName : string ) : Promise < string [ ] > {
684684 if ( ! eName ) {
685- throw new Error ( "eName is required for getting public key " ) ;
685+ throw new Error ( "eName is required for getting public keys " ) ;
686686 }
687687
688688 const result = await this . runQueryInternal (
689- `MATCH (u:User { eName: $eName }) RETURN u.publicKey AS publicKey ` ,
689+ `MATCH (u:User { eName: $eName }) RETURN u.publicKeys AS publicKeys ` ,
690690 { eName } ,
691691 ) ;
692692
693693 if ( ! result . records [ 0 ] ) {
694- return null ;
694+ return [ ] ;
695695 }
696696
697- return result . records [ 0 ] . get ( "publicKey" ) || null ;
697+ const publicKeys = result . records [ 0 ] . get ( "publicKeys" ) ;
698+ // Handle null/undefined and ensure we return an array
699+ if ( ! publicKeys || ! Array . isArray ( publicKeys ) ) {
700+ return [ ] ;
701+ }
702+
703+ return publicKeys ;
698704 }
699705
700706 /**
701- * Sets or updates the public key for a given eName.
707+ * Adds a public key to the array for a given eName (appends, avoids duplicates) .
702708 * @param eName - The eName identifier
703- * @param publicKey - The public key to store
709+ * @param publicKey - The public key to add
704710 */
705- async setPublicKey ( eName : string , publicKey : string ) : Promise < void > {
711+ async addPublicKey ( eName : string , publicKey : string ) : Promise < void > {
706712 if ( ! eName ) {
707- throw new Error ( "eName is required for setting public key" ) ;
713+ throw new Error ( "eName is required for adding public key" ) ;
708714 }
709715 if ( ! publicKey ) {
710716 throw new Error ( "publicKey is required" ) ;
711717 }
712718
719+ // Use MERGE to create User if doesn't exist, then append publicKey if not already in array
713720 await this . runQueryInternal (
714721 `MERGE (u:User { eName: $eName })
715- SET u.publicKey = $publicKey` ,
722+ ON CREATE SET u.publicKeys = []
723+ WITH u
724+ WHERE NOT $publicKey IN u.publicKeys
725+ SET u.publicKeys = u.publicKeys + $publicKey` ,
716726 { eName, publicKey } ,
717727 ) ;
718728 }
@@ -803,26 +813,26 @@ export class DbService {
803813 }
804814 }
805815
806- // Copy User node with public key if it exists
816+ // Copy User node with public keys if it exists
807817 try {
808818 const userResult = await this . runQueryInternal (
809- `MATCH (u:User { eName: $eName }) RETURN u.publicKey AS publicKey ` ,
819+ `MATCH (u:User { eName: $eName }) RETURN u.publicKeys AS publicKeys ` ,
810820 { eName } ,
811821 ) ;
812822
813823 if ( userResult . records . length > 0 ) {
814- const publicKey = userResult . records [ 0 ] . get ( "publicKey " ) ;
815- if ( publicKey ) {
824+ const publicKeys = userResult . records [ 0 ] . get ( "publicKeys " ) ;
825+ if ( publicKeys && Array . isArray ( publicKeys ) && publicKeys . length > 0 ) {
816826 console . log (
817- `[MIGRATION] Copying User node with public key for eName: ${ eName } ` ,
827+ `[MIGRATION] Copying User node with public keys for eName: ${ eName } ` ,
818828 ) ;
819829 await targetDbService . runQuery (
820830 `MERGE (u:User { eName: $eName })
821- SET u.publicKey = $publicKey ` ,
822- { eName, publicKey } ,
831+ SET u.publicKeys = $publicKeys ` ,
832+ { eName, publicKeys } ,
823833 ) ;
824834 console . log (
825- `[MIGRATION] User node with public key copied successfully` ,
835+ `[MIGRATION] User node with public keys copied successfully` ,
826836 ) ;
827837 }
828838 }
0 commit comments