Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Distribuidos-Org/ms-alumnos/llms.txt

Use this file to discover all available pages before exploring further.

Send a create_alumno message to register a new student in the system. The service validates all fields using class-validator, hashes the plaintext password with bcrypt (10 rounds) via a TypeORM @BeforeInsert() hook, and then persists the record to the alumnos PostgreSQL table. Both dni and email must be unique across all records.

Message pattern

{ "cmd": "create_alumno" }

Request payload

nombre
string
required
First name of the student. Minimum 2 characters, maximum 50 characters.
apellidoPaterno
string
required
Paternal surname. Minimum 2 characters, maximum 50 characters.
apellidoMaterno
string
Maternal surname. Optional. Maximum 50 characters.
dni
string
required
National ID number. Must be exactly 8 characters. Must be unique across all student records.
edad
number
Age of the student. Optional. Must be an integer.
email
string
required
Email address. Must be a valid email format. Maximum 100 characters. Must be unique across all student records.
celular
string
Phone number. Optional. Maximum 15 characters.
universidad
string
University name. Optional. Maximum 100 characters. Defaults to 'UNMSM' if omitted.
facultad
string
Faculty or school name. Optional. Maximum 100 characters.
profesion
string
Profession. Optional. Maximum 50 characters.
grado
string
Academic degree. Optional. Maximum 50 characters.
egresadoLocal
boolean
Whether the student graduated from a local institution. Optional. Defaults to true.
contrasena
string
required
Password in plaintext. Minimum 6 characters, maximum 60 characters. This value is hashed with bcrypt before storage — the plaintext is never persisted.

Response

The full Alumno entity is returned after a successful insert.
alumnoId
number
Auto-generated primary key for the newly created student record.
nombre
string
First name of the student.
apellidoPaterno
string
Paternal surname.
apellidoMaterno
string
Maternal surname. May be null if not provided.
dni
string
National ID number (8 characters).
edad
number
Age of the student. May be null if not provided.
email
string
Email address.
celular
string
Phone number. May be null if not provided.
universidad
string
University name. Defaults to 'UNMSM'.
facultad
string
Faculty or school name. May be null if not provided.
profesion
string
Profession. May be null if not provided.
grado
string
Academic degree. May be null if not provided.
egresadoLocal
boolean
Whether the student graduated locally. Defaults to true.
The contrasena field is present in the returned entity object, but its value is the bcrypt hash — not the original plaintext. Callers should discard or ignore this field; never display or forward the hash to end users.

Example

import { connect, JSONCodec } from 'nats';

const nc = await connect({ servers: 'nats://localhost:4222' });
const jc = JSONCodec();

const alumno = await nc.request(
  'create_alumno',
  jc.encode({
    nombre: 'Juan',
    apellidoPaterno: 'García',
    apellidoMaterno: 'López',
    dni: '12345678',
    edad: 25,
    email: 'juan.garcia@example.com',
    celular: '987654321',
    universidad: 'UNMSM',
    facultad: 'FISI',
    profesion: 'Ing. Sistemas',
    grado: 'Bachiller',
    egresadoLocal: true,
    contrasena: 'miContrasena123',
  }),
  { timeout: 5000 }
);

console.log(jc.decode(alumno.data));
await nc.drain();

Errors

StatusCause
400Validation failed — a required field is missing, a field exceeds its length constraint, email is not a valid email address, dni is not exactly 8 characters, or contrasena is shorter than 6 characters.
400Unique constraint violation — the supplied dni or email already exists in the database.
The contrasena field is hashed with bcrypt (10 rounds) via a TypeORM @BeforeInsert() hook before the record is saved. The plaintext password is never stored.

Build docs developers (and LLMs) love