the beginning of the idiots
This commit is contained in:
41
qwen/nodejs/models/Tenant.js
Normal file
41
qwen/nodejs/models/Tenant.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// models/Tenant.js
|
||||
// Tenant model definition
|
||||
|
||||
class Tenant {
|
||||
constructor(id, name, subdomain, settings, createdAt, updatedAt) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.subdomain = subdomain;
|
||||
this.settings = settings || {};
|
||||
this.createdAt = createdAt || new Date();
|
||||
this.updatedAt = updatedAt || new Date();
|
||||
}
|
||||
|
||||
// Static method to create a new tenant
|
||||
static create(tenantData) {
|
||||
const id = tenantData.id || require('uuid').v4();
|
||||
return new Tenant(
|
||||
id,
|
||||
tenantData.name,
|
||||
tenantData.subdomain,
|
||||
tenantData.settings
|
||||
);
|
||||
}
|
||||
|
||||
// Method to validate a tenant
|
||||
validate() {
|
||||
if (!this.name || !this.subdomain) {
|
||||
throw new Error('Tenant name and subdomain are required');
|
||||
}
|
||||
|
||||
// Validate subdomain format (alphanumeric and hyphens only)
|
||||
const subdomainRegex = /^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$/;
|
||||
if (!subdomainRegex.test(this.subdomain)) {
|
||||
throw new Error('Invalid subdomain format');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Tenant;
|
||||
50
qwen/nodejs/models/User.js
Normal file
50
qwen/nodejs/models/User.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// models/User.js
|
||||
// User model definition
|
||||
|
||||
class User {
|
||||
constructor(id, email, passwordHash, firstName, lastName, userType, tenantId, createdAt, updatedAt) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
this.passwordHash = passwordHash;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.userType = userType; // 'job-seeker' or 'job-provider'
|
||||
this.tenantId = tenantId;
|
||||
this.createdAt = createdAt || new Date();
|
||||
this.updatedAt = updatedAt || new Date();
|
||||
}
|
||||
|
||||
// Static method to create a new user
|
||||
static create(userData) {
|
||||
const id = userData.id || require('uuid').v4();
|
||||
return new User(
|
||||
id,
|
||||
userData.email,
|
||||
userData.passwordHash,
|
||||
userData.firstName,
|
||||
userData.lastName,
|
||||
userData.userType,
|
||||
userData.tenantId
|
||||
);
|
||||
}
|
||||
|
||||
// Method to validate a user
|
||||
validate() {
|
||||
if (!this.email || !this.passwordHash || !this.firstName || !this.lastName || !this.userType || !this.tenantId) {
|
||||
throw new Error('Missing required fields');
|
||||
}
|
||||
|
||||
if (!['job-seeker', 'job-provider'].includes(this.userType)) {
|
||||
throw new Error('User type must be either job-seeker or job-provider');
|
||||
}
|
||||
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(this.email)) {
|
||||
throw new Error('Invalid email format');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = User;
|
||||
11
qwen/nodejs/models/index.js
Normal file
11
qwen/nodejs/models/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// models/index.js
|
||||
// This would typically connect to the database and export all models
|
||||
// For now, we'll define a simple structure
|
||||
|
||||
const User = require('./User');
|
||||
const Tenant = require('./Tenant');
|
||||
|
||||
module.exports = {
|
||||
User,
|
||||
Tenant
|
||||
};
|
||||
Reference in New Issue
Block a user