feat: Реализован полный CRUD для админ-панели и улучшена функциональность
- Portfolio CRUD: добавление, редактирование, удаление, переключение публикации - Services CRUD: полное управление услугами с возможностью активации/деактивации - Banner system: новая модель Banner с CRUD операциями и аналитикой кликов - Telegram integration: расширенные настройки бота, обнаружение чатов, отправка сообщений - Media management: улучшенная загрузка файлов с оптимизацией изображений и превью - UI improvements: обновлённые админ-панели с rich-text редактором и drag&drop загрузкой - Database: добавлена таблица banners с полями для баннеров и аналитики
This commit is contained in:
195
models/Banner.js
Normal file
195
models/Banner.js
Normal file
@@ -0,0 +1,195 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const Banner = sequelize.define('Banner', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 200]
|
||||
}
|
||||
},
|
||||
subtitle: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
len: [0, 300]
|
||||
}
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
buttonText: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
len: [0, 50]
|
||||
}
|
||||
},
|
||||
buttonUrl: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
isUrl: true
|
||||
}
|
||||
},
|
||||
image: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: 'Banner background image URL'
|
||||
},
|
||||
mobileImage: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: 'Mobile-optimized banner image URL'
|
||||
},
|
||||
position: {
|
||||
type: DataTypes.ENUM('hero', 'secondary', 'footer'),
|
||||
defaultValue: 'hero',
|
||||
allowNull: false
|
||||
},
|
||||
order: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false,
|
||||
comment: 'Display order (lower numbers appear first)'
|
||||
},
|
||||
isActive: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
allowNull: false
|
||||
},
|
||||
startDate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
comment: 'Banner start display date'
|
||||
},
|
||||
endDate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
comment: 'Banner end display date'
|
||||
},
|
||||
clickCount: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false
|
||||
},
|
||||
impressions: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false
|
||||
},
|
||||
targetAudience: {
|
||||
type: DataTypes.ENUM('all', 'mobile', 'desktop'),
|
||||
defaultValue: 'all',
|
||||
allowNull: false
|
||||
},
|
||||
backgroundColor: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
is: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
||||
},
|
||||
comment: 'Hex color code for banner background'
|
||||
},
|
||||
textColor: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
is: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
||||
},
|
||||
comment: 'Hex color code for banner text'
|
||||
},
|
||||
animation: {
|
||||
type: DataTypes.ENUM('none', 'fade', 'slide', 'zoom'),
|
||||
defaultValue: 'none',
|
||||
allowNull: false
|
||||
},
|
||||
metadata: {
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: true,
|
||||
defaultValue: {},
|
||||
comment: 'Additional banner metadata and settings'
|
||||
}
|
||||
}, {
|
||||
tableName: 'banners',
|
||||
timestamps: true,
|
||||
paranoid: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['isActive']
|
||||
},
|
||||
{
|
||||
fields: ['position']
|
||||
},
|
||||
{
|
||||
fields: ['order']
|
||||
},
|
||||
{
|
||||
fields: ['startDate', 'endDate']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Virtual field for checking if banner is currently active
|
||||
Banner.prototype.isCurrentlyActive = function() {
|
||||
if (!this.isActive) return false;
|
||||
|
||||
const now = new Date();
|
||||
|
||||
if (this.startDate && now < this.startDate) return false;
|
||||
if (this.endDate && now > this.endDate) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Method to increment click count
|
||||
Banner.prototype.recordClick = async function() {
|
||||
this.clickCount += 1;
|
||||
await this.save();
|
||||
return this;
|
||||
};
|
||||
|
||||
// Method to increment impressions
|
||||
Banner.prototype.recordImpression = async function() {
|
||||
this.impressions += 1;
|
||||
await this.save();
|
||||
return this;
|
||||
};
|
||||
|
||||
// Static method to get active banners
|
||||
Banner.getActiveBanners = async function(position = null) {
|
||||
const whereClause = {
|
||||
isActive: true
|
||||
};
|
||||
|
||||
if (position) {
|
||||
whereClause.position = position;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
|
||||
return await this.findAll({
|
||||
where: {
|
||||
...whereClause,
|
||||
[require('sequelize').Op.or]: [
|
||||
{ startDate: null },
|
||||
{ startDate: { [require('sequelize').Op.lte]: now } }
|
||||
],
|
||||
[require('sequelize').Op.or]: [
|
||||
{ endDate: null },
|
||||
{ endDate: { [require('sequelize').Op.gte]: now } }
|
||||
]
|
||||
},
|
||||
order: [['order', 'ASC'], ['createdAt', 'DESC']]
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Banner;
|
||||
@@ -1,80 +1,108 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const contactSchema = new mongoose.Schema({
|
||||
const Contact = sequelize.define('Contact', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
this.setDataValue('name', value.trim());
|
||||
}
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
lowercase: true,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isEmail: true
|
||||
},
|
||||
set(value) {
|
||||
this.setDataValue('email', value.toLowerCase().trim());
|
||||
}
|
||||
},
|
||||
phone: {
|
||||
type: String,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
set(value) {
|
||||
this.setDataValue('phone', value ? value.trim() : null);
|
||||
}
|
||||
},
|
||||
company: {
|
||||
type: String,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
set(value) {
|
||||
this.setDataValue('company', value ? value.trim() : null);
|
||||
}
|
||||
},
|
||||
subject: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
this.setDataValue('subject', value.trim());
|
||||
}
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
required: true
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false
|
||||
},
|
||||
serviceInterest: {
|
||||
type: String,
|
||||
enum: ['web-development', 'mobile-app', 'ui-ux-design', 'branding', 'consulting', 'other']
|
||||
type: DataTypes.ENUM('web-development', 'mobile-app', 'ui-ux-design', 'branding', 'consulting', 'other'),
|
||||
allowNull: true
|
||||
},
|
||||
budget: {
|
||||
type: String,
|
||||
enum: ['under-1m', '1m-5m', '5m-10m', '10m-20m', '20m-50m', 'over-50m']
|
||||
type: DataTypes.ENUM('under-1m', '1m-5m', '5m-10m', '10m-20m', '20m-50m', 'over-50m'),
|
||||
allowNull: true
|
||||
},
|
||||
timeline: {
|
||||
type: String,
|
||||
enum: ['asap', '1-month', '1-3-months', '3-6-months', 'flexible']
|
||||
type: DataTypes.ENUM('asap', '1-month', '1-3-months', '3-6-months', 'flexible'),
|
||||
allowNull: true
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
enum: ['new', 'in-progress', 'replied', 'closed'],
|
||||
default: 'new'
|
||||
type: DataTypes.ENUM('new', 'in-progress', 'replied', 'closed'),
|
||||
defaultValue: 'new'
|
||||
},
|
||||
priority: {
|
||||
type: String,
|
||||
enum: ['low', 'medium', 'high', 'urgent'],
|
||||
default: 'medium'
|
||||
type: DataTypes.ENUM('low', 'medium', 'high', 'urgent'),
|
||||
defaultValue: 'medium'
|
||||
},
|
||||
source: {
|
||||
type: String,
|
||||
enum: ['website', 'telegram', 'email', 'phone', 'referral'],
|
||||
default: 'website'
|
||||
type: DataTypes.ENUM('website', 'telegram', 'email', 'phone', 'referral'),
|
||||
defaultValue: 'website'
|
||||
},
|
||||
isRead: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
adminNotes: {
|
||||
type: String
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
ipAddress: {
|
||||
type: String
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
userAgent: {
|
||||
type: String
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
}
|
||||
}, {
|
||||
timestamps: true
|
||||
tableName: 'contacts',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['status', 'createdAt']
|
||||
},
|
||||
{
|
||||
fields: ['isRead', 'createdAt']
|
||||
},
|
||||
{
|
||||
fields: ['email']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
contactSchema.index({ status: 1, createdAt: -1 });
|
||||
contactSchema.index({ isRead: 1, createdAt: -1 });
|
||||
contactSchema.index({ email: 1 });
|
||||
|
||||
module.exports = mongoose.model('Contact', contactSchema);
|
||||
module.exports = Contact;
|
||||
@@ -1,107 +1,121 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const portfolioSchema = new mongoose.Schema({
|
||||
const Portfolio = sequelize.define('Portfolio', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
len: [1, 255]
|
||||
},
|
||||
set(value) {
|
||||
this.setDataValue('title', value.trim());
|
||||
}
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false
|
||||
},
|
||||
shortDescription: {
|
||||
type: String,
|
||||
required: true,
|
||||
maxlength: 200
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: false
|
||||
},
|
||||
category: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ['web-development', 'mobile-app', 'ui-ux-design', 'branding', 'e-commerce', 'other']
|
||||
type: DataTypes.ENUM('web-development', 'mobile-app', 'ui-ux-design', 'branding', 'e-commerce', 'other'),
|
||||
allowNull: false
|
||||
},
|
||||
technologies: {
|
||||
type: DataTypes.ARRAY(DataTypes.STRING),
|
||||
defaultValue: []
|
||||
},
|
||||
images: {
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
technologies: [{
|
||||
type: String,
|
||||
trim: true
|
||||
}],
|
||||
images: [{
|
||||
url: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
isPrimary: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
}],
|
||||
clientName: {
|
||||
type: String,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
set(value) {
|
||||
this.setDataValue('clientName', value ? value.trim() : null);
|
||||
}
|
||||
},
|
||||
projectUrl: {
|
||||
type: String,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
isUrl: true
|
||||
}
|
||||
},
|
||||
githubUrl: {
|
||||
type: String,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
validate: {
|
||||
isUrl: true
|
||||
}
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
enum: ['completed', 'in-progress', 'planning'],
|
||||
default: 'completed'
|
||||
type: DataTypes.ENUM('completed', 'in-progress', 'planning'),
|
||||
defaultValue: 'completed'
|
||||
},
|
||||
featured: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
publishedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
completedAt: {
|
||||
type: Date
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true
|
||||
},
|
||||
isPublished: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
viewCount: {
|
||||
type: Number,
|
||||
default: 0
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
likes: {
|
||||
type: Number,
|
||||
default: 0
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
order: {
|
||||
type: Number,
|
||||
default: 0
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
seo: {
|
||||
metaTitle: String,
|
||||
metaDescription: String,
|
||||
keywords: [String]
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {}
|
||||
}
|
||||
}, {
|
||||
timestamps: true
|
||||
tableName: 'portfolios',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['category', 'publishedAt']
|
||||
},
|
||||
{
|
||||
fields: ['featured', 'publishedAt']
|
||||
},
|
||||
{
|
||||
type: 'gin',
|
||||
fields: ['technologies']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Index for search and sorting
|
||||
portfolioSchema.index({ title: 'text', description: 'text', technologies: 'text' });
|
||||
portfolioSchema.index({ category: 1, publishedAt: -1 });
|
||||
portfolioSchema.index({ featured: -1, publishedAt: -1 });
|
||||
|
||||
// Virtual for primary image
|
||||
portfolioSchema.virtual('primaryImage').get(function() {
|
||||
Portfolio.prototype.getPrimaryImage = function() {
|
||||
if (!this.images || this.images.length === 0) return null;
|
||||
const primary = this.images.find(img => img.isPrimary);
|
||||
return primary || (this.images.length > 0 ? this.images[0] : null);
|
||||
});
|
||||
return primary || this.images[0];
|
||||
};
|
||||
|
||||
portfolioSchema.set('toJSON', { virtuals: true });
|
||||
|
||||
module.exports = mongoose.model('Portfolio', portfolioSchema);
|
||||
module.exports = Portfolio;
|
||||
@@ -1,102 +1,96 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const serviceSchema = new mongoose.Schema({
|
||||
const Service = sequelize.define('Service', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
len: [1, 255]
|
||||
},
|
||||
set(value) {
|
||||
this.setDataValue('name', value.trim());
|
||||
}
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false
|
||||
},
|
||||
shortDescription: {
|
||||
type: String,
|
||||
required: true,
|
||||
maxlength: 150
|
||||
type: DataTypes.STRING(150),
|
||||
allowNull: false
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
required: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
category: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ['development', 'design', 'consulting', 'marketing', 'maintenance']
|
||||
type: DataTypes.ENUM('development', 'design', 'consulting', 'marketing', 'maintenance'),
|
||||
allowNull: false
|
||||
},
|
||||
features: {
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
features: [{
|
||||
name: String,
|
||||
description: String,
|
||||
included: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
}],
|
||||
pricing: {
|
||||
basePrice: {
|
||||
type: Number,
|
||||
required: true,
|
||||
min: 0
|
||||
},
|
||||
currency: {
|
||||
type: String,
|
||||
default: 'KRW'
|
||||
},
|
||||
priceType: {
|
||||
type: String,
|
||||
enum: ['fixed', 'hourly', 'project'],
|
||||
default: 'project'
|
||||
},
|
||||
priceRange: {
|
||||
min: Number,
|
||||
max: Number
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isValidPricing(value) {
|
||||
if (!value.basePrice || value.basePrice < 0) {
|
||||
throw new Error('Base price must be a positive number');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
estimatedTime: {
|
||||
min: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
max: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
enum: ['hours', 'days', 'weeks', 'months'],
|
||||
default: 'days'
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isValidTime(value) {
|
||||
if (!value.min || !value.max || value.min > value.max) {
|
||||
throw new Error('Invalid estimated time range');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
featured: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
order: {
|
||||
type: Number,
|
||||
default: 0
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
tags: {
|
||||
type: DataTypes.ARRAY(DataTypes.STRING),
|
||||
defaultValue: []
|
||||
},
|
||||
portfolio: [{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Portfolio'
|
||||
}],
|
||||
tags: [{
|
||||
type: String,
|
||||
trim: true
|
||||
}],
|
||||
seo: {
|
||||
metaTitle: String,
|
||||
metaDescription: String,
|
||||
keywords: [String]
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {}
|
||||
}
|
||||
}, {
|
||||
timestamps: true
|
||||
tableName: 'services',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['category', 'featured', 'order']
|
||||
},
|
||||
{
|
||||
type: 'gin',
|
||||
fields: ['tags']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
serviceSchema.index({ name: 'text', description: 'text', tags: 'text' });
|
||||
serviceSchema.index({ category: 1, featured: -1, order: 1 });
|
||||
|
||||
module.exports = mongoose.model('Service', serviceSchema);
|
||||
module.exports = Service;
|
||||
@@ -1,116 +1,82 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const siteSettingsSchema = new mongoose.Schema({
|
||||
const SiteSettings = sequelize.define('SiteSettings', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
siteName: {
|
||||
type: String,
|
||||
default: 'SmartSolTech'
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'SmartSolTech'
|
||||
},
|
||||
siteDescription: {
|
||||
type: String,
|
||||
default: 'Innovative technology solutions for modern businesses'
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: 'Innovative technology solutions for modern businesses'
|
||||
},
|
||||
logo: {
|
||||
type: String,
|
||||
default: '/images/logo.png'
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '/images/logo.png'
|
||||
},
|
||||
favicon: {
|
||||
type: String,
|
||||
default: '/images/favicon.ico'
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '/images/favicon.ico'
|
||||
},
|
||||
contact: {
|
||||
email: {
|
||||
type: String,
|
||||
default: 'info@smartsoltech.kr'
|
||||
},
|
||||
phone: {
|
||||
type: String,
|
||||
default: '+82-10-0000-0000'
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
default: 'Seoul, South Korea'
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {
|
||||
email: 'info@smartsoltech.kr',
|
||||
phone: '+82-10-0000-0000',
|
||||
address: 'Seoul, South Korea'
|
||||
}
|
||||
},
|
||||
social: {
|
||||
facebook: String,
|
||||
twitter: String,
|
||||
linkedin: String,
|
||||
instagram: String,
|
||||
github: String,
|
||||
telegram: String
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
telegram: {
|
||||
botToken: String,
|
||||
chatId: String,
|
||||
isEnabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {
|
||||
isEnabled: false
|
||||
}
|
||||
},
|
||||
seo: {
|
||||
metaTitle: {
|
||||
type: String,
|
||||
default: 'SmartSolTech - Technology Solutions'
|
||||
},
|
||||
metaDescription: {
|
||||
type: String,
|
||||
default: 'Professional web development, mobile apps, and digital solutions in Korea'
|
||||
},
|
||||
keywords: {
|
||||
type: String,
|
||||
default: 'web development, mobile apps, UI/UX design, Korea, technology'
|
||||
},
|
||||
googleAnalytics: String,
|
||||
googleTagManager: String
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {
|
||||
metaTitle: 'SmartSolTech - Technology Solutions',
|
||||
metaDescription: 'Professional web development, mobile apps, and digital solutions in Korea',
|
||||
keywords: 'web development, mobile apps, UI/UX design, Korea, technology'
|
||||
}
|
||||
},
|
||||
hero: {
|
||||
title: {
|
||||
type: String,
|
||||
default: 'Smart Technology Solutions'
|
||||
},
|
||||
subtitle: {
|
||||
type: String,
|
||||
default: 'We create innovative digital experiences that drive business growth'
|
||||
},
|
||||
backgroundImage: {
|
||||
type: String,
|
||||
default: '/images/hero-bg.jpg'
|
||||
},
|
||||
ctaText: {
|
||||
type: String,
|
||||
default: 'Get Started'
|
||||
},
|
||||
ctaLink: {
|
||||
type: String,
|
||||
default: '#contact'
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {
|
||||
title: 'Smart Technology Solutions',
|
||||
subtitle: 'We create innovative digital experiences that drive business growth',
|
||||
backgroundImage: '/images/hero-bg.jpg',
|
||||
ctaText: 'Get Started',
|
||||
ctaLink: '#contact'
|
||||
}
|
||||
},
|
||||
about: {
|
||||
title: {
|
||||
type: String,
|
||||
default: 'About SmartSolTech'
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
default: 'We are a team of passionate developers and designers creating cutting-edge technology solutions.'
|
||||
},
|
||||
image: {
|
||||
type: String,
|
||||
default: '/images/about.jpg'
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {
|
||||
title: 'About SmartSolTech',
|
||||
description: 'We are a team of passionate developers and designers creating cutting-edge technology solutions.',
|
||||
image: '/images/about.jpg'
|
||||
}
|
||||
},
|
||||
maintenance: {
|
||||
isEnabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
default: 'We are currently performing maintenance. Please check back soon.'
|
||||
type: DataTypes.JSONB,
|
||||
defaultValue: {
|
||||
isEnabled: false,
|
||||
message: 'We are currently performing maintenance. Please check back soon.'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
tableName: 'site_settings',
|
||||
timestamps: true
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('SiteSettings', siteSettingsSchema);
|
||||
module.exports = SiteSettings;
|
||||
@@ -1,75 +1,78 @@
|
||||
const mongoose = require('mongoose');
|
||||
const { DataTypes } = require('sequelize');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
const User = sequelize.define('User', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
lowercase: true,
|
||||
trim: true
|
||||
validate: {
|
||||
isEmail: true
|
||||
},
|
||||
set(value) {
|
||||
this.setDataValue('email', value.toLowerCase().trim());
|
||||
}
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true,
|
||||
minlength: 6
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
len: [6, 255]
|
||||
}
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
len: [1, 100]
|
||||
},
|
||||
set(value) {
|
||||
this.setDataValue('name', value.trim());
|
||||
}
|
||||
},
|
||||
role: {
|
||||
type: String,
|
||||
enum: ['admin', 'moderator'],
|
||||
default: 'admin'
|
||||
type: DataTypes.ENUM('admin', 'moderator'),
|
||||
defaultValue: 'admin'
|
||||
},
|
||||
avatar: {
|
||||
type: String,
|
||||
default: null
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
lastLogin: {
|
||||
type: Date,
|
||||
default: null
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true
|
||||
}
|
||||
}, {
|
||||
timestamps: true
|
||||
});
|
||||
|
||||
// Hash password before saving
|
||||
userSchema.pre('save', async function(next) {
|
||||
if (!this.isModified('password')) return next();
|
||||
|
||||
try {
|
||||
const salt = await bcrypt.genSalt(12);
|
||||
this.password = await bcrypt.hash(this.password, salt);
|
||||
next();
|
||||
} catch (error) {
|
||||
next(error);
|
||||
tableName: 'users',
|
||||
timestamps: true,
|
||||
hooks: {
|
||||
beforeSave: async (user) => {
|
||||
if (user.changed('password')) {
|
||||
const salt = await bcrypt.genSalt(12);
|
||||
user.password = await bcrypt.hash(user.password, salt);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Compare password method
|
||||
userSchema.methods.comparePassword = async function(candidatePassword) {
|
||||
// Instance methods
|
||||
User.prototype.comparePassword = async function(candidatePassword) {
|
||||
return bcrypt.compare(candidatePassword, this.password);
|
||||
};
|
||||
|
||||
// Update last login
|
||||
userSchema.methods.updateLastLogin = function() {
|
||||
User.prototype.updateLastLogin = function() {
|
||||
this.lastLogin = new Date();
|
||||
return this.save();
|
||||
};
|
||||
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
module.exports = User;
|
||||
25
models/index.js
Normal file
25
models/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
// Import models
|
||||
const User = require('./User');
|
||||
const Portfolio = require('./Portfolio');
|
||||
const Service = require('./Service');
|
||||
const Contact = require('./Contact');
|
||||
const SiteSettings = require('./SiteSettings');
|
||||
const Banner = require('./Banner');
|
||||
|
||||
// Define associations here if needed
|
||||
// For example:
|
||||
// Service.belongsToMany(Portfolio, { through: 'ServicePortfolio' });
|
||||
// Portfolio.belongsToMany(Service, { through: 'ServicePortfolio' });
|
||||
|
||||
// Export models and sequelize instance
|
||||
module.exports = {
|
||||
sequelize,
|
||||
User,
|
||||
Portfolio,
|
||||
Service,
|
||||
Contact,
|
||||
SiteSettings,
|
||||
Banner
|
||||
};
|
||||
Reference in New Issue
Block a user