All files / services/profile prepareLastWills.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                    47x 14x 18x 108x 108x         18x                  
import { MaterialSymbol } from 'material-symbols'
import { sidebarElements } from '../../../content/sidebar'
import { LastWillProfile } from '../../app/(dynamic)/(pages)/profile/last-will/page'
import { LastWillProfileResponse } from '../api/profile/lastWill'
 
/**
 * Prepare last wills for profile page.
 * @param lastWills to prepare
 * @returns prepared last wills
 */
export const prepareLastWills = (lastWills: LastWillProfileResponse[]): LastWillProfile[] => {
	return lastWills.map((lastWill) => {
		const steps = sidebarElements.map((element) => {
			const isProgressKeyPresent = lastWill.progressKeys.includes(element.page)
			return {
				label: element.title,
				icon: (isProgressKeyPresent ? 'check_circle' : 'cancel') as MaterialSymbol,
			}
		})
		return {
			id: lastWill._id,
			title: lastWill.testator !== '' ? lastWill.testator : 'Testament',
			createdAt: new Date(lastWill.createdAt),
			updatedAt: new Date(lastWill.updatedAt),
			steps: steps,
		}
	})
}