@rs-tech-hub/nestjs-profile
v1.0.1
Published
A NestJS module to manage user profiles within a NestJS application.
Readme
@rs-tech-hub/nestjs-profile
User profile management for NestJS applications with GraphQL support. Create and update user profiles with personal information, avatar, and demographics.
🔑 License
This package requires a valid commercial license. A valid license key must be configured to use this package.
Visit https://rstechhub.gumroad.com to purchase a license.
✨ Features
- 👤 Profile Management - Create and update user profiles
- 🔒 Authentication Required - Protected GraphQL operations
- 🌍 Demographics - Store country, date of birth, salutation
- 🖼️ Avatar Support - Profile avatar URL management
- 📊 GraphQL API - Mutations and queries for profile operations
- 🔐 User-Scoped - Profiles automatically linked to authenticated users
📋 Prerequisites
- Node.js ≥ 18
- TypeScript ≥ 5.1.0
- NestJS ≥ 11.1.6
- Prisma ORM v7.0+
- GraphQL support configured in your NestJS application
📦 Installation
npm install @rs-tech-hub/nestjs-profile \
@rs-tech-hub/nestjs-auth-core \
@rs-tech-hub/nestjs-license-validator \
@rs-tech-hub/nestjs-prisma \
@rs-tech-hub/nestjs-service-operationyarn add @rs-tech-hub/nestjs-profile \
@rs-tech-hub/nestjs-auth-core \
@rs-tech-hub/nestjs-license-validator \
@rs-tech-hub/nestjs-prisma \
@rs-tech-hub/nestjs-service-operationpnpm add @rs-tech-hub/nestjs-profile \
@rs-tech-hub/nestjs-auth-core \
@rs-tech-hub/nestjs-license-validator \
@rs-tech-hub/nestjs-prisma \
@rs-tech-hub/nestjs-service-operation🚀 Module Registration
Import the module in your NestJS application:
import { Module } from '@nestjs/common';
import { ProfileModule } from '@rs-tech-hub/nestjs-profile';
@Module({
imports: [ProfileModule],
})
export class AppModule {}📖 GraphQL API
Mutations
Create Profile
mutation {
profile_create(
createProfileInput: {
avatarUrl: "https://example.com/avatar.jpg"
salutation: "Mr"
firstName: "John"
lastName: "Doe"
dateOfBirth: "1990-01-15"
country: "United States"
}
) {
profile {
id
avatarUrl
Salutation
firstName
lastName
dateOfBirth
country
userId
}
}
}Update Profile
mutation {
updateProfile(
updateProfileInput: {
avatarUrl: "https://example.com/new-avatar.jpg"
country: "Canada"
}
) {
id
avatarUrl
country
userId
}
}Queries
Get Current User Profile
query {
profile_get {
id
avatarUrl
Salutation
firstName
lastName
dateOfBirth
country
userId
}
}🔧 Repository Usage
Inject the repository in your own services:
import { Injectable } from '@nestjs/common';
import { ProfileRepository } from '@rs-tech-hub/nestjs-profile';
@Injectable()
export class UserService {
constructor(private profileRepository: ProfileRepository) {}
async getUserProfile(userId: string) {
return this.profileRepository.findUnique({ userId });
}
async createProfile(data: ProfileCreateDto) {
return this.profileRepository.create(data);
}
async updateProfile(userId: string, data: ProfileUpdateInput) {
return this.profileRepository.update({ userId }, data);
}
async deleteProfile(userId: string) {
return this.profileRepository.delete({ userId });
}
}📝 Data Types
ProfileSalutations Enum
Available salutations for user profiles:
MR- MisterMS- MissMRS- MissusDR- DoctorPROF- Professor
Input Fields
Create Profile Input
| Field | Type | Required | Description | | ----------- | ------ | -------- | ------------------------------- | | avatarUrl | string | ❌ | URL to profile avatar image | | salutation | string | ✅ | User salutation (Mr, Ms, etc.) | | firstName | string | ✅ | User's first name | | lastName | string | ✅ | User's last name | | dateOfBirth | Date | ✅ | User's date of birth (ISO 8601) | | country | string | ✅ | User's country |
Update Profile Input
| Field | Type | Required | Description | | --------- | ------ | -------- | --------------------------- | | avatarUrl | string | ❌ | URL to profile avatar image | | country | string | ❌ | User's country |
All fields are optional in update operations. Only provided fields will be updated.
🔒 Authentication
All GraphQL operations require authentication. The package uses @rs-tech-hub/nestjs-auth-core for JWT authentication:
- profile_create - Protected with
GqlAuthGuard - profile_get - Protected with
GqlAuthGuard, returns current user's profile - updateProfile - Protected with
GqlAuthGuard, updates current user's profile
// Authentication is handled automatically
// The current user is injected via @CurrentUser() decorator
@Query(() => [ProfileServiceOutput])
@UseGuards(GqlAuthGuard)
async profile_get(@CurrentUser() user: AuthenticatedUser) {
// user.sub contains the authenticated user ID
return this.profileRepository.findUnique({ userId: user.sub });
}⚠️ Error Codes
| Error Code | Description |
| ------------------------------- | ----------------------- |
| profile-error:creation-failed | Profile creation failed |
| profile-error:update-failed | Profile update failed |
| profile-error:not-found | Profile not found |
💡 Best Practices
- One Profile Per User: Each user should have exactly one profile
- Validate Dates: Ensure dateOfBirth is in valid ISO 8601 format
- Avatar URLs: Validate avatar URLs before storing
- Country Codes: Use standardized country names or ISO codes
- Update Selectively: Only update fields that have changed
- Handle Not Found: Gracefully handle cases where profile doesn't exist
📄 License
This package requires a valid commercial license. See LICENSE.txt for details. By using this software, you agree to the terms outlined in the Software License Agreement (SLA.md). The license grants you specific rights to use, modify, and deploy the software within the scope defined in the agreement. For full terms, conditions, and restrictions, please refer to the Software License Agreement.
Release Notes
1.0.0
- Initial release
1.0.1
- Fixes profile_get Graphql endpoint
- Updates profile_update Graphql endpoint
- Updates internal license handling
🆘 Support
For technical support and inquiries:
- Email: [email protected]
- Website: https://rs-tech-hub.com
