MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / syncEmail

Function syncEmail

apps/web/services/accounts/sync.ts:83–133  ·  view source on GitHub ↗
({
  status,
  accountId,
  pathDomain,
}: {
  status: SyncStatus;
  accountId: string;
  pathDomain: string | null;
})

Source from the content-addressed store, hash-verified

81}
82
83async function syncEmail({
84 status,
85 accountId,
86 pathDomain,
87}: {
88 status: SyncStatus;
89 accountId: string;
90 pathDomain: string | null;
91}) {
92 try {
93 const account = await prisma.accounts.findUnique({
94 where: { id: accountId },
95 });
96 if (account) {
97 const admins = await prisma.users.findMany({
98 where: {
99 role: { in: [Roles.ADMIN, Roles.OWNER] },
100 accountsId: account.id,
101 },
102 include: {
103 auth: true,
104 },
105 });
106 if (admins.length > 0) {
107 await Promise.all(
108 admins.map(async (admin) => {
109 const email = admin.auth?.email;
110 if (!email) {
111 return Promise.resolve();
112 }
113 if (status === SyncStatus.IN_PROGRESS) {
114 return SyncMailer.start({ to: email });
115 }
116 if (status === SyncStatus.DONE) {
117 return SyncMailer.end({
118 to: email,
119 url: `https://www.linen.dev/s/${pathDomain}`,
120 });
121 }
122 if (status === SyncStatus.ERROR) {
123 return SyncMailer.error({ to: email });
124 }
125 return Promise.resolve();
126 })
127 );
128 }
129 }
130 } catch (exception) {
131 console.error('Failed to send sync emails: ', exception);
132 }
133}
134
135function identifySyncType(
136 account:

Callers 1

Calls 4

mapMethod · 0.80
errorMethod · 0.65
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected