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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ jobs:
run: npx eslint ${CHANGED_FILES}

- name: Check for formatting errors
run: npm run format:check
env:
CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
run: npm run format:check ${CHANGED_FILES}

- name: Run Typescript Type-Checker
run: npm run typecheck
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ Core features include:

## Image Upload

To enable image upload functionalities create an images folder in the root of the project
To enable image upload functionalities create an images folder in the root of the project
2 changes: 2 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const config: CodegenConfig = {

EventAttendee: "../models/EventAttendee#InterfaceEventAttendee",

UserFamily: "../models/userFamily#InterfaceUserFamily",

Feedback: "../models/Feedback#InterfaceFeedback",

// File: '../models/File#InterfaceFile',
Expand Down
20 changes: 20 additions & 0 deletions sample_data/userFamilies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"_id": "60f18f31b7e5c4a2a4c3f905",
"title": "Smith Family",
"users": [
"64378abd85008f171cf2990d",
"65378abd85008f171cf2990d",
"66378abd85008f171cf2990d"
]
},
{
"_id": "60f18f31b7e5c4a2a4c3f906",
"title": "Johnson Family",
"users": [
"66378abd85008f171cf2990d",
"65378abd85008f171cf2990d",
"64378abd85008f171cf2990d"
]
}
]
17 changes: 17 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ type Mutation {
addUserCustomData(dataName: String!, dataValue: Any!, organizationId: ID!): UserCustomData!
addUserImage(file: String!): User!
addUserToGroupChat(chatId: ID!, userId: ID!): GroupChat!
addUserToUserFamily(familyId: ID!, userId: ID!): UserFamily!
adminRemoveEvent(eventId: ID!): Event!
adminRemoveGroup(groupId: ID!): GroupChat!
assignUserTag(input: ToggleUserTagAssignInput!): User
Expand All @@ -543,6 +544,7 @@ type Mutation {
createPlugin(pluginCreatedBy: String!, pluginDesc: String!, pluginName: String!, uninstalledOrgs: [ID!]): Plugin!
createPost(data: PostInput!, file: String): Post
createSampleOrganization: Boolean!
createUserFamily(data: createUserFamilyInput!): UserFamily!
createUserTag(input: CreateUserTagInput!): UserTag
deleteAdvertisementById(id: ID!): DeletePayload!
deleteDonationById(id: ID!): DeletePayload!
Expand Down Expand Up @@ -574,7 +576,9 @@ type Mutation {
removePost(id: ID!): Post
removeSampleOrganization: Boolean!
removeUserCustomData(organizationId: ID!): UserCustomData!
removeUserFamily(familyId: ID!): UserFamily!
removeUserFromGroupChat(chatId: ID!, userId: ID!): GroupChat!
removeUserFromUserFamily(familyId: ID!, userId: ID!): UserFamily!
removeUserImage: User!
removeUserTag(id: ID!): UserTag
revokeRefreshTokenForUser: Boolean!
Expand Down Expand Up @@ -1073,6 +1077,14 @@ type UserEdge {
node: User!
}

type UserFamily {
_id: ID!
admins: [User!]!
creator: User!
title: String
users: [User!]!
}

input UserInput {
appLanguageCode: String
email: EmailAddress!
Expand Down Expand Up @@ -1204,4 +1216,9 @@ input createGroupChatInput {
organizationId: ID!
title: String!
userIds: [ID!]!
}

input createUserFamilyInput {
title: String!
userIds: [ID!]!
}
44 changes: 22 additions & 22 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function setNodeEnvironment(): Promise<void> {
*/
async function accessAndRefreshTokens(
accessTokenSecret: string | null,
refreshTokenSecret: string | null
refreshTokenSecret: string | null,
): Promise<void> {
const config = dotenv.parse(fs.readFileSync(".env"));

Expand Down Expand Up @@ -183,12 +183,12 @@ async function askForTransactionLogPath(): Promise<string> {
break;
} catch {
console.error(
"The file is not readable/writable. Please enter a valid file path."
"The file is not readable/writable. Please enter a valid file path.",
);
}
} else {
console.error(
"Invalid path or file does not exist. Please enter a valid file path."
"Invalid path or file does not exist. Please enter a valid file path.",
);
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ async function redisConfiguration(): Promise<void> {
*/
async function askForSuperAdminEmail(): Promise<string> {
console.log(
"\nPlease make sure to register with this email before logging in.\n"
"\nPlease make sure to register with this email before logging in.\n",
);
const { email } = await inquirer.prompt([
{
Expand Down Expand Up @@ -558,7 +558,7 @@ async function recaptcha(): Promise<void> {
async function recaptchaSiteKey(): Promise<void> {
if (process.env.RECAPTCHA_SITE_KEY) {
console.log(
`\nreCAPTCHA site key already exists with the value ${process.env.RECAPTCHA_SITE_KEY}`
`\nreCAPTCHA site key already exists with the value ${process.env.RECAPTCHA_SITE_KEY}`,
);
}

Expand Down Expand Up @@ -636,14 +636,14 @@ function abort(): void {
async function twoFactorAuth(): Promise<void> {
console.log("\nIMPORTANT");
console.log(
"\nEnsure that you have Two-Factor Authentication set up on your Google Account."
"\nEnsure that you have Two-Factor Authentication set up on your Google Account.",
);
console.log("\nVisit Url: https://myaccount.google.com");
console.log(
"\nSelect Security and under Signing in to Google section select App Passwords."
"\nSelect Security and under Signing in to Google section select App Passwords.",
);
console.log(
"\nClick on Select app section and choose Other(Custom name), enter talawa as the custom name and press Generate button."
"\nClick on Select app section and choose Other(Custom name), enter talawa as the custom name and press Generate button.",
);

const { email, password } = await inquirer.prompt([
Expand Down Expand Up @@ -741,7 +741,7 @@ async function importData(): Promise<void> {
abort();
}
console.log(`Output: ${stdout}`);
}
},
);
}
}
Expand All @@ -762,7 +762,7 @@ type VerifySmtpConnectionReturnType = {
* be `true` and the `error` property will be `null`. If the SMTP connection verification fails
*/
async function verifySmtpConnection(
config: Record<string, string>
config: Record<string, string>,
): Promise<VerifySmtpConnectionReturnType> {
const transporter = nodemailer.createTransport({
host: config.SMTP_HOST,
Expand Down Expand Up @@ -829,7 +829,7 @@ async function configureSmtp(): Promise<void> {

if (!isValidSmtpConfig) {
console.error(
"Invalid SMTP configuration. Please provide all required parameters."
"Invalid SMTP configuration. Please provide all required parameters.",
);
return;
}
Expand All @@ -838,7 +838,7 @@ async function configureSmtp(): Promise<void> {

if (!success) {
console.error(
"SMTP configuration verification failed. Please check your SMTP settings."
"SMTP configuration verification failed. Please check your SMTP settings.",
);
if (error instanceof Error) {
console.log(error.message);
Expand Down Expand Up @@ -876,7 +876,7 @@ async function main(): Promise<void> {
refreshToken: string | null = "";
if (process.env.ACCESS_TOKEN_SECRET) {
console.log(
`\nAccess token secret already exists with the value:\n${process.env.ACCESS_TOKEN_SECRET}`
`\nAccess token secret already exists with the value:\n${process.env.ACCESS_TOKEN_SECRET}`,
);
}
const { shouldGenerateAccessToken } = await inquirer.prompt({
Expand All @@ -892,7 +892,7 @@ async function main(): Promise<void> {

if (process.env.REFRESH_TOKEN_SECRET) {
console.log(
`\nRefresh token secret already exists with the value:\n${process.env.REFRESH_TOKEN_SECRET}`
`\nRefresh token secret already exists with the value:\n${process.env.REFRESH_TOKEN_SECRET}`,
);
}
const { shouldGenerateRefreshToken } = await inquirer.prompt({
Expand All @@ -918,7 +918,7 @@ async function main(): Promise<void> {
if (shouldLog) {
if (process.env.LOG_PATH) {
console.log(
`\n Log path already exists with the value:\n${process.env.LOG_PATH}`
`\n Log path already exists with the value:\n${process.env.LOG_PATH}`,
);
}
let logPath: string | null = null;
Expand Down Expand Up @@ -997,7 +997,7 @@ async function main(): Promise<void> {
// MongoDB configuration
if (process.env.MONGO_DB_URL) {
console.log(
`\nMongoDB URL already exists with the value:\n${process.env.MONGO_DB_URL}`
`\nMongoDB URL already exists with the value:\n${process.env.MONGO_DB_URL}`,
);

const { shouldSetupMongo } = await inquirer.prompt({
Expand All @@ -1016,7 +1016,7 @@ async function main(): Promise<void> {
}
if (process.env.RECAPTCHA_SECRET_KEY) {
console.log(
`\nreCAPTCHA secret key already exists with the value ${process.env.RECAPTCHA_SECRET_KEY}`
`\nreCAPTCHA secret key already exists with the value ${process.env.RECAPTCHA_SECRET_KEY}`,
);
}
const { shouldSetRecaptcha } = await inquirer.prompt({
Expand All @@ -1032,12 +1032,12 @@ async function main(): Promise<void> {
}

console.log(
"\n You can configure either SMTP or Mail for sending emails through Talawa.\n"
"\n You can configure either SMTP or Mail for sending emails through Talawa.\n",
);

if (process.env.MAIL_USERNAME) {
console.log(
`Mail username already exists with the value ${process.env.MAIL_USERNAME}`
`Mail username already exists with the value ${process.env.MAIL_USERNAME}`,
);
}

Expand Down Expand Up @@ -1070,7 +1070,7 @@ async function main(): Promise<void> {

if (process.env.LAST_RESORT_SUPERADMIN_EMAIL) {
console.log(
`\nSuper Admin of last resort already exists with the value ${process.env.LAST_RESORT_SUPERADMIN_EMAIL}`
`\nSuper Admin of last resort already exists with the value ${process.env.LAST_RESORT_SUPERADMIN_EMAIL}`,
);
}

Expand All @@ -1093,7 +1093,7 @@ async function main(): Promise<void> {
) {
if (process.env.MAIL_USERNAME) {
console.log(
"No super admin email configured, setting it to mail username's value."
"No super admin email configured, setting it to mail username's value.",
);
}
const config = dotenv.parse(fs.readFileSync(".env"));
Expand Down Expand Up @@ -1135,7 +1135,7 @@ async function main(): Promise<void> {
await setImageUploadSize(imageSizeLimit * 1000);

console.log(
"\nCongratulations! Talawa API has been successfully setup! 🥂🎉"
"\nCongratulations! Talawa API has been successfully setup! 🥂🎉",
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ app.use(
helmet({
contentSecurityPolicy:
process.env.NODE_ENV === "production" ? undefined : false,
})
}),
);
app.use(mongoSanitize());
app.use(cors());
Expand All @@ -81,8 +81,8 @@ app.use(
':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms',
{
stream: stream,
}
)
},
),
);

app.use("/images", express.static(path.join(__dirname, "./../images")));
Expand All @@ -97,7 +97,7 @@ app.get("/", (req, res) =>
res.json({
"talawa-version": "v1",
status: "healthy",
})
}),
);

export default app;
8 changes: 4 additions & 4 deletions src/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const logWarningForSuperAdminEnvVariable = async (): Promise<void> => {
if (isVariablePresentInEnvFile) {
logger.warn(
"\x1b[1m\x1b[33m%s\x1b[0m",
"The LAST_RESORT_SUPERADMIN_EMAIL variable configured in your .env file poses a security risk. We strongly recommend that you remove it if not required. Please refer to the documentation in the INSTALLATION.md file.You have created super admin, please remove the LAST_RESORT_SUPERADMIN_EMAIL variable from .env file if you don't require it"
"The LAST_RESORT_SUPERADMIN_EMAIL variable configured in your .env file poses a security risk. We strongly recommend that you remove it if not required. Please refer to the documentation in the INSTALLATION.md file.You have created super admin, please remove the LAST_RESORT_SUPERADMIN_EMAIL variable from .env file if you don't require it",
);
}
} else {
if (!isVariablePresentInEnvFile) {
logger.warn(
"\x1b[1m\x1b[33m%s\x1b[0m",
"To create your first Super Admin, the LAST_RESORT_SUPERADMIN_EMAIL parameter needs to be set in the .env file. Please refer to the documentation in the INSTALLATION.md file."
"To create your first Super Admin, the LAST_RESORT_SUPERADMIN_EMAIL parameter needs to be set in the .env file. Please refer to the documentation in the INSTALLATION.md file.",
);
}
}
Expand All @@ -28,12 +28,12 @@ export const logIssues = async (): Promise<void> => {
const issues = getEnvIssues();
if (issues) {
logger.error(
"Invalid environment variables found in your .env file, check the errors below!"
"Invalid environment variables found in your .env file, check the errors below!",
);
console.error(
generateErrorMessage(issues, {
delimiter: { error: "\\n" },
})
}),
);
} else {
logger.info("The environment variables are valid!");
Expand Down
4 changes: 2 additions & 2 deletions src/config/plugins/loadPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const loadPlugins = async (): Promise<void> => {
});
logger.info(
"\x1b[1m\x1b[32m%s\x1b[0m",
`Uploaded Plugins in ${databaseTitle} `
`Uploaded Plugins in ${databaseTitle} `,
);
} else {
//plugin data already present
logger.info(
"\x1b[1m\x1b[32m%s\x1b[0m",
`Plugin data already present at ${databaseTitle}`
`Plugin data already present at ${databaseTitle}`,
);
}
};
Expand Down
12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,24 @@ export const LENGTH_VALIDATION_ERROR = {
PARAM: "stringValidation",
};

export const USER_FAMILY_MIN_MEMBERS_ERROR_CODE = {
MESSAGE: "InputValidationError",
CODE: "membersInUserFamilyLessThanOne",
PARAM: "membersInUserFamilyLessThanOne",
};

export const REGEX_VALIDATION_ERROR = {
MESSAGE: "Error: Entered value must be a valid string",
CODE: "string.notValid",
PARAM: "stringValidation",
};

export const USER_FAMILY_NOT_FOUND_ERROR = {
MESSAGE: "Error: User Family Not Found",
CODE: "userfamilyNotFound",
PARAM: "userfamilyNotFound",
};

export const USER_NOT_AUTHORIZED_SUPERADMIN = {
MESSAGE: "Error: Current user must be a SUPERADMIN",
CODE: "role.notValid.superadmin",
Expand Down
Loading