Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/app.module.spec.ts

This file was deleted.

35 changes: 34 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { SequelizeModule } from '@nestjs/sequelize';
import { LoggerModule } from 'nestjs-pino';
import { nanoid } from 'nanoid';
import configuration from './config/configuration';
import { HealthModule } from './modules/health/health.module';
import { JmapModule } from './modules/infrastructure/jmap/jmap.module';
import { EmailModule } from './modules/email/email.module';
import { AuthModule } from './modules/auth/auth.module';
import { AccountModule } from './modules/account/account.module';

@Module({
imports: [
Expand Down Expand Up @@ -43,11 +45,42 @@ import { AuthModule } from './modules/auth/auth.module';
load: [configuration],
isGlobal: true,
}),
SequelizeModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
dialect: 'postgres',
autoLoadModels: true,
synchronize: false,
host: configService.get('database.host'),
port: configService.get('database.port'),
username: configService.get('database.username'),
password: configService.get('database.password'),
database: configService.get('database.name'),
pool: {
max: 20,
min: 0,
idle: 20000,
acquire: 20000,
},
dialectOptions: configService.get('isProduction')
? {
ssl: {
require: true,
rejectUnauthorized: false,
},
application_name: 'mail-server',
}
: {},
logging: configService.get('isDevelopment') ? console.log : false,
}),
}),
EventEmitterModule.forRoot({ wildcard: true, delimiter: '.' }),
HealthModule,
JmapModule,
EmailModule,
AuthModule,
AccountModule,
],
controllers: [],
providers: [],
Expand Down
21 changes: 21 additions & 0 deletions src/modules/account/account.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Module } from '@nestjs/common';
import { SequelizeModule } from '@nestjs/sequelize';
import {
MailAccountModel,
MailAddressModel,
MailDomainModel,
MailProviderAccountModel,
} from './models/index.js';

@Module({
imports: [
SequelizeModule.forFeature([
MailAccountModel,
MailAddressModel,
MailDomainModel,
MailProviderAccountModel,
]),
],
exports: [SequelizeModule],
})
export class AccountModule {}
4 changes: 4 additions & 0 deletions src/modules/account/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { MailAccountModel } from './mail-account.model.js';
export { MailAddressModel } from './mail-address.model.js';
export { MailDomainModel } from './mail-domain.model.js';
export { MailProviderAccountModel } from './mail-provider-account.model.js';
32 changes: 32 additions & 0 deletions src/modules/account/models/mail-account.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
AllowNull,
Column,
DataType,
Default,
HasMany,
Model,
PrimaryKey,
Table,
Unique,
} from 'sequelize-typescript';
import { MailAddressModel } from './mail-address.model.js';

@Table({
underscored: true,
timestamps: true,
tableName: 'mail_accounts',
})
export class MailAccountModel extends Model {
@PrimaryKey
@Default(DataType.UUIDV4)
@Column(DataType.UUID)
declare id: string;

@AllowNull(false)
@Unique
@Column(DataType.UUID)
declare driveUserUuid: string;

@HasMany(() => MailAddressModel)
declare addresses: MailAddressModel[];
}
60 changes: 60 additions & 0 deletions src/modules/account/models/mail-address.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
AllowNull,
BelongsTo,
Column,
DataType,
Default,
ForeignKey,
HasOne,
Index,
Model,
PrimaryKey,
Table,
Unique,
} from 'sequelize-typescript';
import { MailAccountModel } from './mail-account.model.js';
import { MailDomainModel } from './mail-domain.model.js';
import { MailProviderAccountModel } from './mail-provider-account.model.js';

@Table({
underscored: true,
timestamps: true,
tableName: 'mail_addresses',
})
export class MailAddressModel extends Model {
@PrimaryKey
@Default(DataType.UUIDV4)
@Column(DataType.UUID)
declare id: string;

@AllowNull(false)
@ForeignKey(() => MailAccountModel)
@Index
@Column(DataType.UUID)
declare mailAccountId: string;

@AllowNull(false)
@Unique
@Column(DataType.STRING(255))
declare address: string;

@AllowNull(false)
@ForeignKey(() => MailDomainModel)
@Index
@Column(DataType.UUID)
declare domainId: string;

@AllowNull(false)
@Default(false)
@Column(DataType.BOOLEAN)
declare isDefault: boolean;

@BelongsTo(() => MailAccountModel)
declare account: MailAccountModel;

@BelongsTo(() => MailDomainModel)
declare domain: MailDomainModel;

@HasOne(() => MailProviderAccountModel)
declare providerAccount: MailProviderAccountModel;
}
37 changes: 37 additions & 0 deletions src/modules/account/models/mail-domain.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
AllowNull,
Column,
DataType,
Default,
HasMany,
Model,
PrimaryKey,
Table,
Unique,
} from 'sequelize-typescript';
import { MailAddressModel } from './mail-address.model.js';

@Table({
underscored: true,
timestamps: true,
tableName: 'mail_domains',
})
export class MailDomainModel extends Model {
@PrimaryKey
@Default(DataType.UUIDV4)
@Column(DataType.UUID)
declare id: string;

@AllowNull(false)
@Unique
@Column(DataType.STRING(255))
declare domain: string;

@AllowNull(false)
@Default('active')
@Column(DataType.STRING(20))
declare status: string;

@HasMany(() => MailAddressModel)
declare addresses: MailAddressModel[];
}
43 changes: 43 additions & 0 deletions src/modules/account/models/mail-provider-account.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
AllowNull,
BelongsTo,
Column,
DataType,
Default,
ForeignKey,
Model,
PrimaryKey,
Table,
Unique,
} from 'sequelize-typescript';
import { MailAddressModel } from './mail-address.model.js';

@Table({
underscored: true,
timestamps: true,
tableName: 'mail_provider_accounts',
indexes: [{ unique: true, fields: ['provider', 'external_id'] }],
})
export class MailProviderAccountModel extends Model {
@PrimaryKey
@Default(DataType.UUIDV4)
@Column(DataType.UUID)
declare id: string;

@AllowNull(false)
@Unique
@ForeignKey(() => MailAddressModel)
@Column(DataType.UUID)
declare mailAddressId: string;

@AllowNull(false)
@Column(DataType.STRING)
declare provider: string;

@AllowNull(false)
@Column(DataType.STRING(255))
declare externalId: string;

@BelongsTo(() => MailAddressModel)
declare address: MailAddressModel;
}
Loading