Skip to content

Commit

Permalink
fix: adds inviting user column to table, route, validation and ui cha…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
cephaschapa committed Mar 8, 2024
1 parent 727c015 commit 918f4f9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/migrations/20240213184421-city-invite.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = {
type: Sequelize.STRING,
allowNull:true,
},
inviting_user_id: {
type: Sequelize.UUID,
allowNull: true,
references: {
model:'User',
key: 'user_id'
}
},
status: {
type: Sequelize.STRING,
allowNull:false,
Expand Down
2 changes: 1 addition & 1 deletion app/src/app/api/v0/city/invite/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const POST = apiHandler(async (req, { params, session }) => {
{ email: body.email, reason: "invite", city: body.cityId },
process.env.VERIFICATION_TOKEN_SECRET,
{
expiresIn: "1h",
expiresIn: "24h",
},
);

Expand Down
1 change: 1 addition & 0 deletions app/src/components/Modals/add-user-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const AddUserModal: FC<AddUserModalProps> = ({
cityId: defaultCityId!,
email: data.email!,
userId: res?.data?.userId,
invitingUserId: userInfo! && userInfo?.userId!,
}).then((res: any) => {
onClose();
if (res?.error?.status == 400) {
Expand Down
1 change: 0 additions & 1 deletion app/src/lib/emails/InviteUserTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default function InviteUserTemplate({
backgroundSize: "cover",
height: "32px",
width: "32px",
borderRadius: "50px",
backgroundOrigin: "content-box",
marginTop: "28px",
marginRight: "16px",
Expand Down
12 changes: 12 additions & 0 deletions app/src/models/CityInvite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CityInviteAttributes {
id: string;
cityId?: string;
userId?: string;
invitingUserId?: string;
status?: string;
created?: Date;
lastUpdated?: Date;
Expand All @@ -21,6 +22,7 @@ export type CityInviteCreationAttributes = Optional<
export type CityInviteOptionalAttributes =
| "cityId"
| "userId"
| "invitingUserId"
| "status"
| "created"
| "lastUpdated";
Expand All @@ -32,6 +34,7 @@ export class CityInvite
id!: string;
cityId?: string | undefined;
userId?: string | undefined;
invitingUserId?: string | undefined;
status?: string | undefined;
created?: Date | undefined;
lastUpdated?: Date | undefined;
Expand Down Expand Up @@ -64,6 +67,15 @@ export class CityInvite
type: DataTypes.STRING(255),
allowNull: true,
},
invitingUserId: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: "User",
key: "user_id",
},
field: "inviting_user_id",
},
status: {
type: DataTypes.STRING(255),
allowNull: true,
Expand Down
8 changes: 7 additions & 1 deletion app/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,13 @@ export const api = createApi({
// User invitation to city
inviteUser: builder.mutation<
UserInviteResponse,
{ cityId: string; name?: string; email: string; userId: string }
{
cityId: string;
name?: string;
email: string;
userId: string;
invitingUserId: string;
}
>({
query: (data) => {
return {
Expand Down
1 change: 1 addition & 0 deletions app/src/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type CreateUserFileRequetData = z.infer<typeof createUserFileRequset>;

export const createUserInvite = z.object({
userId: z.string().optional(),
invitingUserId: z.string().uuid(),
email: z.string().email(),
name: z.string(),
cityId: z.string(),
Expand Down

0 comments on commit 918f4f9

Please sign in to comment.