import Inject from "@entity-access/entity-access/dist/di/di.js"; import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js"; import SocialMailContext from "../../model/SocialMailContext.js"; import { globalEnv } from "../../../common/globalEnv.js"; import { WebSiteHost } from "../../model/entities/WebSiteHost.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import EmailAddressService from "../../services/EmailAddressService.js"; export default class CreateSocialSiteWorkflow extends Workflow<{ userID: number, domainName: string, templateID?: any, name?: string }> { // channelContact: { mailboxID: number; emailAddressID: number; }; async run() { await this.createSite(); // if (this.input.domainName) { // await this.sendWelcomeMessage(); // } } // @UniqueActivity // async sendWelcomeMessage( // @Inject db?: SocialMailContext, // @Inject wcs?: WebClientService // ) { // db.verifyFilters = false; // const { name, domainName } = this.input; // const { mailboxID, emailAddressID } = this.channelContact; // let htmlBody = await (await wcs.getUIPackageInfo()) // .downloadText("/content/emails/welcome-post/welcome-post.html"); // htmlBody = htmlBody.replaceAll("$DOMAIN_NAME$", domainName); // const now = DateTime.now; // db.emails.add({ // senderName: name, // senderID: emailAddressID, // subject: `Welcome to the ${domainName}`, // recipients: [ // db.emailRecipients.add({ // emailAddressID: mailboxID, // type: "to" // }) // ], // htmlBody, // dateReceived: now, // dateCreated: now, // dateSent: now, // received: false, // status: "scheduled" // }); // await db.saveChanges(); // } @UniqueActivity async createSite( @Inject db?: SocialMailContext, @Inject eas?: EmailAddressService ) { db.verifyFilters = false; const user = await db.users.where(this.input, (x, p) => x.userID === p.userID).first(); const now = DateTime.now; const hosts = [] as WebSiteHost[]; const { userID, domainName, templateID, name } = this.input; // add a hosting domain.. let channelDomains = void 0; // let author: MailboxContact; if (domainName) { const domainID = await eas.getOrCreateDomain(domainName); db.hostedDomains.add({ domainID, enableReceive: true, enableSend: true, domainUsers: [ db.hostedDomainUsers.add({ userID, isAdmin: true }) ] }); // create social.... db.mailboxes.add({ domainID, username: "social", name: "Social", authorEmail: "info@" + domainName, authorName: this.input.name, addSubscribers: user.contactEmail, isChannel: true, }); await db.saveChanges(); channelDomains = [db.websiteChannelDomains.add({ domainID })]; hosts.push(db.websiteFolderHosts.add({ host: domainName })); hosts.push(db.websiteFolderHosts.add({ host: "www." + domainName })); await db.saveChanges(); } await using tx = await db.connection.createTransaction(); if (globalEnv.wildcardDomain) { hosts.push(db.websiteFolderHosts.add({ host: `${user.userName}.${globalEnv.wildcardDomain}` })); } db.appFiles.add({ name: name + " Web Site (" + user.userName + ")" , dateCreated: now, dateUpdated: now, isFolder: true, contentType: "application/site", creatorID: user.userID, websiteFolder: db.websiteFolders.add({ isStatic: true, hosts, templateID, fromEmail: "info@" + domainName, supportEmail: user.contactEmail, title: name, channelDomains }), }); await db.saveChanges(); await tx.commit(); // return { mailboxID: author.mailboxID, emailAddressID: author.emailAddressID }; } }