- Add settlement category with handshake emoji (🤝) - Create settlement page for recording debt payments with user → user flow - Implement settlement detection and visual styling across all views - Add conditional "Settle Debts" button (hidden when balance is 0) - Style settlement payments distinctly in recent activity with large profile pictures - Add settlement flow styling in payments overview with green theme - Update backend validation and Mongoose schema for settlement category - Fix settlement receiver detection with proper user flow logic 🤝 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
import mongoose from 'mongoose';
|
|
|
|
export interface IPayment {
|
|
_id?: string;
|
|
title: string;
|
|
description?: string;
|
|
amount: number;
|
|
currency: string;
|
|
paidBy: string; // username/nickname of the person who paid
|
|
date: Date;
|
|
image?: string; // path to uploaded image
|
|
category: 'groceries' | 'shopping' | 'travel' | 'restaurant' | 'utilities' | 'fun' | 'settlement';
|
|
splitMethod: 'equal' | 'full' | 'proportional' | 'personal_equal';
|
|
createdBy: string; // username/nickname of the person who created the payment
|
|
createdAt?: Date;
|
|
updatedAt?: Date;
|
|
}
|
|
|
|
const PaymentSchema = new mongoose.Schema(
|
|
{
|
|
title: {
|
|
type: String,
|
|
required: true,
|
|
trim: true
|
|
},
|
|
description: {
|
|
type: String,
|
|
trim: true
|
|
},
|
|
amount: {
|
|
type: Number,
|
|
required: true,
|
|
min: 0
|
|
},
|
|
currency: {
|
|
type: String,
|
|
required: true,
|
|
default: 'CHF',
|
|
enum: ['CHF'] // For now only CHF as requested
|
|
},
|
|
paidBy: {
|
|
type: String,
|
|
required: true,
|
|
trim: true
|
|
},
|
|
date: {
|
|
type: Date,
|
|
required: true,
|
|
default: Date.now
|
|
},
|
|
image: {
|
|
type: String,
|
|
trim: true
|
|
},
|
|
category: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['groceries', 'shopping', 'travel', 'restaurant', 'utilities', 'fun', 'settlement'],
|
|
default: 'groceries'
|
|
},
|
|
splitMethod: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['equal', 'full', 'proportional', 'personal_equal'],
|
|
default: 'equal'
|
|
},
|
|
createdBy: {
|
|
type: String,
|
|
required: true,
|
|
trim: true
|
|
}
|
|
},
|
|
{
|
|
timestamps: true,
|
|
toJSON: { virtuals: true },
|
|
toObject: { virtuals: true }
|
|
}
|
|
);
|
|
|
|
PaymentSchema.virtual('splits', {
|
|
ref: 'PaymentSplit',
|
|
localField: '_id',
|
|
foreignField: 'paymentId'
|
|
});
|
|
|
|
export const Payment = mongoose.model<IPayment>("Payment", PaymentSchema); |