Skip to content

Commit cb300b8

Browse files
committed
Merge branch 'main' of github.com:Apillon/nft-studio-simplet
2 parents 8c5741a + 7e58006 commit cb300b8

14 files changed

Lines changed: 737 additions & 248 deletions

File tree

backend/src/config/values.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export enum ValidatorErrorCode {
100100
EMAIL_OR_WALLET_REQUIRED = 422014,
101101
DATA_MODEL_STATUS_MISSING = 422100,
102102
DATA_MODEL_INVALID_STATUS = 422101,
103+
DUPLICATED_MAIL = 422102,
104+
DUPLICATED_WALLET = 422103,
103105
}
104106

105107
/**

backend/src/cron.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ export class Cron {
120120
apiUrl: env.APILLON_API_URL,
121121
key: env.APILLON_KEY,
122122
secret: env.APILLON_SECRET,
123-
logLevel: LogLevel.VERBOSE,
123+
logLevel:
124+
env.APP_ENV === 'production'
125+
? LogLevel.ERROR
126+
: LogLevel.VERBOSE,
124127
}).collection(env.COLLECTION_UUID)
125128
: null;
126129

backend/src/lib/claim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function claim(user: User): Promise<string> {
1010
apiUrl: env.APILLON_API_URL,
1111
key: env.APILLON_KEY,
1212
secret: env.APILLON_SECRET,
13-
logLevel: LogLevel.VERBOSE,
13+
logLevel: env.APP_ENV === 'production' ? LogLevel.ERROR : LogLevel.VERBOSE,
1414
}).collection(env.COLLECTION_UUID);
1515

1616
validateAirdropStatus(user.airdrop_status);

backend/src/lib/job.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ const sendClaimEmails = async (job: JobType, mysql: MySql) => {
9696
apiUrl: env.APILLON_API_URL,
9797
key: env.APILLON_KEY,
9898
secret: env.APILLON_SECRET,
99-
logLevel: LogLevel.VERBOSE,
99+
logLevel:
100+
env.APP_ENV === 'production' ? LogLevel.ERROR : LogLevel.VERBOSE,
100101
}).collection(env.COLLECTION_UUID)
101102
: null;
102103

@@ -181,7 +182,7 @@ const sendClaimEmails = async (job: JobType, mysql: MySql) => {
181182
}
182183
}
183184

184-
writeLog(LogType.ERROR, updates);
185+
writeLog(LogType.SQL, updates);
185186

186187
if (updates.length > 0) {
187188
const sql = `

backend/src/lib/logger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export function writeLog(
2828
functionSource = '',
2929
error?: Error,
3030
) {
31+
if (type === LogType.SQL && env.APP_ENV === 'production') {
32+
// Do not log SQL queries in production
33+
return;
34+
}
35+
3136
if (env.LOG_TARGET == 'console') {
3237
// setTheme({
3338
// info: [bgYellow, black],

backend/src/lib/node-mailer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function SmtpSendTemplate(
9898
senderName ? senderName : env.SMTP_NAME_FROM
9999
} <${
100100
senderEmail ? senderEmail : env.SMTP_EMAIL_FROM
101-
}>" to "${mailAddresses.join(';')}"`,
101+
}>" to ${mailAddresses.length} recipients.`,
102102
'node-mailer.ts',
103103
'SmtpSendTemplate',
104104
);

backend/src/middlewares/claim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ export function ClaimGuard(req: Request, _res: Response, next: NextFunction) {
4444
AuthorizationErrorCode.UNSUPPORTED_CLAIM_TYPE,
4545
context,
4646
`claim-middleware/validateRoute/${context.env.CLAIM_TYPE}`,
47-
),
47+
),
4848
);
4949
}

backend/src/middlewares/logger.ts

Lines changed: 0 additions & 88 deletions
This file was deleted.

backend/src/models/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ export class User extends BaseSqlModel {
208208
`
209209
SELECT 1
210210
FROM user
211-
WHERE email <> @email
211+
WHERE id <> @id
212212
AND wallet = @wallet;
213213
`,
214214
{
215-
email: this.email,
215+
id: this.id,
216216
wallet: this.wallet,
217217
},
218218
);

backend/src/routes/create-user.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Application } from 'express';
22
import { NextFunction, Request, Response } from '../http';
3-
import { PopulateStrategy } from '../config/values';
3+
import { PopulateStrategy, ValidatorErrorCode } from '../config/values';
44
import { AuthenticateAdmin } from '../middlewares/authentication';
55
import { BatchUsers } from '../models/batch-users';
6-
import { ValidationError } from '../lib/errors';
6+
import { ResourceError, ValidationError } from '../lib/errors';
77

88
/**
99
* Installs new route on the provided application.
@@ -21,6 +21,30 @@ export function inject(app: Application) {
2121

2222
export async function resolve(req: Request, res: Response): Promise<void> {
2323
const { context, body } = req;
24+
25+
const usersToCreate = body.users;
26+
27+
const emailSet = new Set<string>();
28+
const walletSet = new Set<string>();
29+
30+
for (const user of usersToCreate) {
31+
const { email, wallet } = user;
32+
33+
if (email && emailSet.has(email)) {
34+
throw new ResourceError(ValidatorErrorCode.DUPLICATED_MAIL);
35+
}
36+
if (wallet && walletSet.has(wallet)) {
37+
throw new ResourceError(ValidatorErrorCode.DUPLICATED_WALLET);
38+
}
39+
40+
if (email) {
41+
emailSet.add(email);
42+
}
43+
if (wallet) {
44+
walletSet.add(wallet);
45+
}
46+
}
47+
2448
const users = new BatchUsers({}, context).populate(
2549
body,
2650
PopulateStrategy.ADMIN,

0 commit comments

Comments
 (0)