Skip to main content

Overview

The RecordService class provides a high-level interface for managing records in the Simple Manager Mobile application. It handles all CRUD operations and includes validation logic for record management. Location: src/application/services/RecordService.ts

Methods

create

Creates a new record with auto-generated ID and timestamps.
async create(title: string, type: string): Promise<Record>
title
string
required
The title of the record
type
string
required
The type/category of the record
record
Record
The newly created record object with the following properties:
id
string
Auto-generated UUID for the record
title
string
The record title
type
string
The record type
createdAt
string
ISO 8601 timestamp of creation
updatedAt
string
ISO 8601 timestamp of last update
isDeleted
boolean
Soft delete flag (default: false)
Example Usage
const recordService = new RecordService();

const newRecord = await recordService.create(
  'Project Alpha',
  'project'
);

console.log(newRecord.id); // "550e8400-e29b-41d4-a716-446655440000"
console.log(newRecord.title); // "Project Alpha"

list

Retrieves all records from the repository.
async list(): Promise<Record[]>
records
Record[]
Array of all record objects in the system
Example Usage
const recordService = new RecordService();

const allRecords = await recordService.list();

allRecords.forEach(record => {
  console.log(`${record.title} (${record.type})`);
});

delete

Performs a soft delete on a record by marking it as deleted.
async delete(id: string): Promise<void>
id
string
required
The unique identifier of the record to delete
Example Usage
const recordService = new RecordService();

await recordService.delete('550e8400-e29b-41d4-a716-446655440000');

// Record is now soft-deleted (isDeleted = true)

update

Updates an existing record and refreshes the updatedAt timestamp.
async update(record: Record): Promise<void>
record
Record
required
The complete record object with updated values. Must include:
  • id (string): Record identifier
  • title (string): Record title
  • type (string): Record type
  • createdAt (string): Original creation timestamp
  • isDeleted (boolean): Deletion status
  • subtitle (string, optional): Record subtitle
  • metadata (string, optional): Additional metadata
  • userId (string, optional): Associated user ID
Example Usage
const recordService = new RecordService();

// Fetch existing record
const records = await recordService.list();
const record = records[0];

// Modify record
record.title = 'Updated Project Name';
record.subtitle = 'New subtitle';

// Save changes
await recordService.update(record);

// updatedAt timestamp is automatically updated

existsByTitle

Checks if a record with the given title already exists (case-insensitive).
async existsByTitle(title: string): Promise<boolean>
title
string
required
The title to check for existence
exists
boolean
Returns true if a record with the given title exists, false otherwise
Example Usage
const recordService = new RecordService();

const exists = await recordService.existsByTitle('Project Alpha');

if (exists) {
  console.log('A record with this title already exists');
} else {
  await recordService.create('Project Alpha', 'project');
}
Note: The title comparison is case-insensitive, so “Project Alpha” and “project alpha” are considered identical.

Record Entity Structure

The Record interface used throughout this service:
interface Record {
  id: string;              // Unique identifier (UUID)
  title: string;           // Record title
  subtitle?: string;       // Optional subtitle
  metadata?: string;       // Optional metadata
  type: string;            // Record type/category
  userId?: string;         // Optional user association
  createdAt: string;       // ISO 8601 creation timestamp
  updatedAt: string;       // ISO 8601 last update timestamp
  isDeleted: boolean;      // Soft delete flag
}

Complete Example

import { RecordService } from '@/src/application/services/RecordService';

// Initialize service
const recordService = new RecordService();

// Create a new record
const newRecord = await recordService.create('Meeting Notes', 'note');
console.log('Created:', newRecord.id);

// Check if title exists
const exists = await recordService.existsByTitle('Meeting Notes');
console.log('Exists:', exists); // true

// List all records
const allRecords = await recordService.list();
console.log('Total records:', allRecords.length);

// Update a record
newRecord.subtitle = 'Q1 Planning Meeting';
newRecord.metadata = JSON.stringify({ location: 'Conference Room A' });
await recordService.update(newRecord);

// Soft delete a record
await recordService.delete(newRecord.id);
console.log('Record deleted');

Dependencies

  • RecordRepository: Handles data persistence layer operations
  • expo-crypto: Provides UUID generation functionality
  • Record Entity: Domain entity defining the record structure

Notes

  • All timestamps are stored in ISO 8601 format
  • Delete operations are soft deletes (sets isDeleted flag)
  • The service automatically manages createdAt and updatedAt timestamps
  • Title existence checks are case-insensitive

Build docs developers (and LLMs) love