diff --git a/package-lock.json b/package-lock.json index e48e1c6..df2f585 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,8 +7,10 @@ "dependencies": { "@types/node": "^20.5.0", "axios": "^1.4.0", + "class-transformer": "^0.5.1", "ldapts": "^6.0.0", "mysql": "^2.18.1", + "reflect-metadata": "^0.1.13", "replace-in-file": "^7.0.1", "sqlite3": "^5.1.6", "ts-mailcow-api": "^0.8.4", @@ -1144,6 +1146,11 @@ "node": ">=10" } }, + "node_modules/class-transformer": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==" + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -5630,6 +5637,11 @@ "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" }, + "class-transformer": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==" + }, "clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", diff --git a/package.json b/package.json index f4d6891..203e81f 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,10 @@ "dependencies": { "@types/node": "^20.5.0", "axios": "^1.4.0", + "class-transformer": "^0.5.1", "ldapts": "^6.0.0", "mysql": "^2.18.1", + "reflect-metadata": "^0.1.13", "replace-in-file": "^7.0.1", "sqlite3": "^5.1.6", "ts-mailcow-api": "^0.8.4", diff --git a/src/mailcowDB.ts b/src/mailcowDB.ts index 63414b5..2ed8870 100644 --- a/src/mailcowDB.ts +++ b/src/mailcowDB.ts @@ -1,96 +1,152 @@ import { DataSource } from 'typeorm'; import { ContainerConfig } from './types'; +import 'reflect-metadata'; +import { plainToClass } from 'class-transformer'; // Connection options for the DB let dataSource; -/** - * Initialize database connection. Setup database if it does not yet exist - */ -export async function initializeMailcowDB(config: ContainerConfig): Promise { - dataSource = new DataSource({ - type: 'mariadb', - host: '172.22.1.251', - port: 3306, - username: 'mailcow', - password: config.DB_PASSWORD, - database: 'mailcow', - }); - - await dataSource.initialize() - .catch((error) => { - console.log(error); - }); - - const test = await dataSource - .createQueryBuilder() - .select('c_defaults') - .from('sogo_user_profile', 'profile') - .where('c_uid = "m9006@gewis.nl"') - .getRawOne() as Test; - - console.log(test); - console.log('=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-'); - console.log(test.SOGoMailIdentities); - -} -export interface Test { +export class Test { SOGoCalendarCategoriesColors: SOGoCalendarCategoriesColors; + SOGoGravatarEnabled: number; + LocaleCode: string; + SOGoMailComposeFontSize: number; + SOGoMailReceiptNonRecipientAction: string; + SOGoDayStartTime: string; + SOGoAlternateAvatar: string; + SOGoLoginModule: string; + SOGoLDAPGroupExpansionEnabled: number; + SOGoCalendarCategories: string[]; + SOGoTOTPEnabled: number; + emailSeparatorKeys: number[]; + SOGoDayEndTime: string; + SOGoMailComposeMessageType: string; + SOGoCalendarWeekdays: string[]; + hasActiveExternalSieveScripts: number; + SOGoShortDateFormat: string; + SOGoMailSignaturePlacement: string; + SOGoMailMessageForwarding: string; + ckLocaleCode: string; + SOGoMailReceiptOutsideDomainAction: string; + Forward: Forward; + SOGoTimeZone: string; + SOGoMailReceiptAllow: string; + UserTimeZoneSecondsFromGMT: number; + SOGoMailComposeWindow: string; + SOGoTimeFormat: string; + Vacation: Vacation; + SOGoRememberLastModule: number; + SOGoCalendarTasksDefaultClassification: string; + SOGoPasswordRecoveryMode: string; + SOGoRefreshViewCheck: string; + SOGoCalendarDefaultReminder: string; + SOGoMailAutoSave: number; + SOGoMailLabelsColors: { [key: string]: string[] }; + SOGoLongDateFormat: string; + SOGoMailReceiptAnyAction: string; + SOGoMailAutoMarkAsReadDelay: number; + SOGoDefaultCalendar: string; + SOGoMailReplyPlacement: string; + SOGoAppointmentSendEMailNotifications: number; + SOGoFirstWeekOfYear: string; + SOGoSelectedAddressBook: string; + SOGoCalendarEventsDefaultClassification: string; + SOGoAnimationMode: string; + SOGoPasswordRecoveryQuestion: string; + SOGoMailAddOutgoingAddresses: number; + AuxiliaryMailAccounts: any[]; + SOGoFirstDayOfWeek: number; + SOGoLanguage: string; + SOGoContactsCategories: string[]; + SOGoMailIdentities: SOGoMailIdentity[]; + SOGoMailDisplayRemoteInlineImages: string; } +/** + * Initialize database connection. Setup database if it does not yet exist + */ +export async function initializeMailcowDB(config: ContainerConfig): Promise { + dataSource = new DataSource({ + type: 'mariadb', + host: '172.22.1.251', + port: 3306, + username: 'mailcow', + password: config.DB_PASSWORD, + database: 'mailcow', + }); + + await dataSource.initialize() + .catch((error) => { + console.log(error); + }); + + const test = await dataSource + .createQueryBuilder() + .select('c_defaults') + .from(Test, 'sogo_user_profile') + .where('c_uid = "m9006@gewis.nl"') + .getOneOrFail(); + + console.log(test); + console.log('=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-'); + console.log(test.SOGoMailIdentities); + +} + + export interface Forward { forwardAddress: any[]; }