Skip to content

Commit

Permalink
better quick-messages/list endpoint handling
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jun 18, 2024
1 parent 809fb74 commit 183fe08
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
8 changes: 1 addition & 7 deletions backend/src/controllers/QuickMessageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ type StoreData = {
userId: number | number;
};

type FindParams = {
companyId: string;
userId: string;
};

export const index = async (req: Request, res: Response): Promise<Response> => {
const { searchParam, pageNumber, userId } = req.query as IndexQuery;
const { companyId } = req.user;
Expand Down Expand Up @@ -139,8 +134,7 @@ export const findList = async (
req: Request,
res: Response
): Promise<Response> => {
const params = req.query as FindParams;
const records: QuickMessage[] = await FindService(params);
const records: QuickMessage[] = await FindService({userId: parseInt(req.user.id,10), companyId: req.user.companyId});

return res.status(200).json(records);
};
12 changes: 6 additions & 6 deletions backend/src/services/QuickMessageService/FindService.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Op } from "sequelize";
import QuickMessage from "../../models/QuickMessage";
import Company from "../../models/Company";
import CheckSettings, { GetCompanySetting } from "../../helpers/CheckSettings";
import { GetCompanySetting } from "../../helpers/CheckSettings";

type Params = {
companyId: string;
userId: string;
companyId: number;
userId: number;
};

type QuickMessageWhere = {
companyId: string;
userId?: string;
companyId: number;
userId?: number;
}

const FindService = async ({ companyId, userId }: Params): Promise<QuickMessage[]> => {
const where: QuickMessageWhere = {
companyId,
}

const quickMessagesSetting = await GetCompanySetting(parseInt(companyId,10), "quickMessages","individual");
const quickMessagesSetting = await GetCompanySetting(companyId, "quickMessages","individual");

if (quickMessagesSetting === "individual") {
where.userId = userId
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/MessageInputCustom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ const CustomInput = (props) => {

useEffect(() => {
async function fetchData() {
const companyId = localStorage.getItem("companyId");
const messages = await listQuickMessages({ companyId, userId: user.id });
const messages = await listQuickMessages();
const options = messages.map((m) => {
let truncatedMessage = m.message;
if (isString(truncatedMessage) && truncatedMessage.length > 35) {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/hooks/useQuickMessages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ const useQuickMessages = () => {
return data;
}

const list = async (params) => {
const list = async () => {
const { data } = await api.request({
url: '/quick-messages/list',
method: 'GET',
params
});
return data;
}
Expand Down

0 comments on commit 183fe08

Please sign in to comment.